Link to home
Start Free TrialLog in
Avatar of slgal
slgal

asked on

Create SQL Server DSN

Hi,
I wanna create a SQL Server DSN programatically using WinAPI, anybody can give me sample coding?

Thx
ASKER CERTIFIED SOLUTION
Avatar of deepakg
deepakg

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of slgal
slgal

ASKER

As I know, there is a API function called "SQLConfigDataSource", I have been sucessfully use it for Access database. Can I use it us SQL Server?

Thx
Yes, You can use this API also like this

#If WIN32 Then
          Dim intRet As Long
      #Else
          Dim intRet As Integer
      #End If
      Dim strDriver As String
      Dim strAttributes As String

      'Set the driver to SQL Server because it is most common.
      strDriver = "SQL Server"
      'Set the attributes delimited by null.
      'See driver documentation for a complete
      'list of supported attributes.
      strAttributes = "SERVER=SomeServer" & Chr$(0)
      strAttributes = strAttributes & "DESCRIPTION=Temp DSN" & Chr$(0)
      strAttributes = strAttributes & "DSN=DSN_TEMP" & Chr$(0)
      strAttributes = strAttributes & "DATABASE=pubs" & Chr$(0)
      strAttributes = strAttributes & "UID=sa" & Chr$(0)
      strAttributes = strAttributes & "PWD=" & Chr$(0)
      'To show dialog, use Form1.Hwnd instead of vbAPINull.
      intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, _
      strDriver, strAttributes)
      If intRet Then
          MsgBox "DSN Created"
      Else
          MsgBox "Create Failed"
      End If

Hope this helps...

Deepak.
Avatar of Éric Moreau
Take a look at the RegisterDatabase (of DAO) or rdoRegisterDatabase (of RDO). It registers perfectly.
Avatar of slgal

ASKER

Sorry for such a long delay. Can you tell me where I can find the documentation on this topic? I can find the function declaration in MSDN, but the constant declaration of the winapi is not available. Also, driver documentation is not available :<

Thx
Hi slgal,
Long time indeed!!
As far as the documentation is concerned, check the MSDN with the foll:
HOWTO: Programmatically Create a DSN for SQL Server with VB
Constant declarations can be obtained from API Viewer or Win32api.txt file (search this file on the HDD)
Even I was not able to obtain driver specific documentation, which is something I need at times while connecting VB with Oracle/DB2, etc.
Get back anytime..
Cheers,
Deepak.
Avatar of slgal

ASKER

Thx, even I cannot find those ODBC constant declaration in Win32api, I think it's time to give you the points :>