Connection using ODBC

G

Gabriel Carulias

Hello friends, I have a problem. I hope that you can help me.
My problem is that I need to create a connection ODBC in run-time. The
application is an Access file that runs a VB code. The code that I run is:

#If Win32 Then
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
#Else
Private Declare Function SQLConfigDataSource Lib "ODBCINST.DLL" _
(ByVal hwndParent As Integer, ByVal fRequest As Integer, ByVal _
lpszDriver As String, ByVal lpszAttributes As String) As Integer
#End If
strAttributes = "DATABASE=" & strDatabaseName & Chr$(0)
strAttributes = strAttributes & "DESCRIPTION=" & strDescription & Chr$(0)
strAttributes = strAttributes & "DSN=" & strDataSourceName & Chr$(0)
strAttributes = strAttributes & "SERVER=" & strServer & Chr$(0)

‘If I put the 2 line below, not generate the connection, and I need that the
connection has a user Id and password

strAttributes = strAttributes & "UID=" & strUID & Chr$(0)
strAttributes = strAttributes & "PWD=" & strPwd & Chr$(0)


intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, strDriver,
strAttributes)

Thank you, and if you need everything please tell me
 
T

TC

Gabriel, please don't MULTI-POST. Instead, CROSS-post. Look those terms
up on the web, to see why multi-posting is BAD and makes everyone MAD!
:)

HTH,
TC
 
T

TC

No problems :)

Do you need a /double/ chr$(0) at the end of strAttributes?

This page:
http://msdn.microsoft.com/library/d...ry/en-us/odbc/htm/odbcsqlconfigdatasource.asp
says that the Attributes parameter is described here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcconfigdsn.asp
, and that page shows a double null character at the end of the
attributes string. Perhaps if you do not have the double null,
SQLConfigDataSource walks off the end of the string & gets confused?

HTH,
TC
 
G

Gabriel Carulias

Friend TC, i so that, but don´t work god.
My english is not good for write, if i read i undestand but if i need write,
i cant.
i don´t know wy don´t work.
thank you.
 
T

TC

Sorry Gabriel, I can not think of anything else.

I hope that someone else can help you.

Good luck :)

TC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top