Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creation of system DSN

Status
Not open for further replies.

swetham

Programmer
May 5, 2010
257
DE
Can anyone provide me with the code to create system DSN for ms access (.accdb) with password?
 
I found this code:



However, when I have needed to use ODBC I use a File DSN. I just create the File DSN on my computer, then copy it to the target machine as part of the installation process. To update the DSN just edit the File DSN - it's a text file and easy to edit.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thanks for providing the link but some errors are coming,
1) LEFT property does not have parameters
2) Creation failed

I need system DSN for ms access because it is used for crystal reports
 
I have used the following code,

Const ODBC_ADD_SYS_DSN = 4 'Add data source
Const ODBC_CONFIG_SYS_DSN = 5 'Configure (edit) data source
Const ODBC_REMOVE_SYS_DSN = 6 'Remove data source

Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" (ByVal _
hwndParent As Long, ByVal fRequest As Long, ByVal _
lpszDriver As String, ByVal lpszAttributes As String) As Long


Function Build_SystemDSN(ByVal DSN_NAME As String, ByVal Db_Path As String)

Dim ret%, Driver$, Attributes$

Driver = "Microsoft Access Driver (*.MDB)" & Chr(0)
Attributes = "DSN=" & DSN_NAME & Chr(0)
Attributes = Attributes & "Uid=Admin" & Chr(0) & "pwd=" & Chr(0)
Attributes = Attributes & "DBQ=" & Db_Path & Chr(0)

ret = SQLConfigDataSource(0, ODBC_ADD_SYS_DSN, Driver, Attributes)


'ret is equal to 1 on success and 0 if there is an error
If ret <> 1 Then
MsgBox("DSN Creation Failed")
End If

End Function


But i am getting the error as "Attempted to read or write protected memory. This is often an indication that other memory is corrupt.". Can anyone please help me?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top