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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help in making DSN through the code!!!

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
hi
i am trying to make the DSn through the code. here is my code---


#If Win32 Then
Dim intRet As Long
#Else
Dim intRet As Integer
#End If

Dim strDriver As String
Dim strAttributes As String
Dim sourceFile As String
Dim destinationFile As String
Dim res
Dim cn As New ADODB.Connection
Dim rst As New ADODB.Recordset

sourceFile = App.Path & "\salesconnect.mdb"
destinationFile = App.Path & "\salesconnect" & CompCode & ".mdb"

res = CopyFile(sourceFile, destinationFile, False)
'DBEngine.CompactDatabase sourceFile, destinationFile
strDriver = "Microsoft Access Driver (*.mdb)"
strAttributes = "SERVER=\\vishal\c\mydocu~1\pjtDsnComp" & Chr$(0)
strAttributes = strAttributes & "DESCRIPTION=Temp DSN" & Chr$(0)
strAttributes = strAttributes & "DSN=" & "salesconnect" & CompCode & Chr$(0)
strAttributes = strAttributes & "DATABASE=c:\mydocu~1\pjtDsnComp\salesConnect.mdb" '" & CompCode & ".mdb" & Chr$(0) '& App.Path & "salesconnect" & CompCode & Chr$(0)
strAttributes = strAttributes & "UID=sa" & Chr$(0)
strAttributes = strAttributes & "PWD=" & Chr$(0)

intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_SYS_DSN, strDriver, strAttributes)
cn.Open "dsn = salesconnectC011"
rst.Open "settings", cn, adOpenKeyset, adLockOptimistic, adCmdTable
MsgBox rst(0)
If intRet Then
createDsn = True
Else
createDsn = False
End If

where SQLConfigDatasource is the function of odbccp32.dll
my problem is that the DSn is being made but it is blank i.e no database is accepted in the DSn

need urgent Help!!!

thanks
regards
Vishal
 
someone asked this same question in the Win32 API VB forum, I answered him, I posted a FAQ concerning this here in the FAQ Section of this forum, expect to see it shortly, in the meantime you can download a sample VB6 project I wrote that does the exact thing (so you dont have to cut and paste from the FAQ)

Karl
kb244@kb244.com
Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top