Microsoft KB Archive/287668

= How to use SQLConfigDataSource to create an Access system DSN =

Article ID: 287668

Article Last Modified on 3/26/2007

-

APPLIES TO


 * Microsoft Office Access 2007
 * Microsoft Office Access 2003
 * Microsoft Access 2002 Standard Edition

-



This article was previously published under Q287668



Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies to a Microsoft Access database (.mdb or accdb) and to a Microsoft Access project (.adp).

For a Microsoft Access 2000 version of this article, see 231156.



SUMMARY
You cannot create a system DSN by using the RegisterDatabase method. To create a system DSN, use the ODBC API call for SQLConfigDataSource.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.



MORE INFORMATION
The following example uses the API call for SQLConfigDataSource to create a system DSN. The example creates a data source for the sample database Northwind.mdb when the database is located at C:\Northwind.mdb.  Copy the sample database Northwind.mdb to the root directory of drive C. Create a new Access database.  Create a module and type the following lines in the Declarations section: Option Explicit 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 &quot;ODBCCP32.DLL&quot; (ByVal _  hwndParent As Long, ByVal fRequest As Long, ByVal _   lpszDriver As String, ByVal lpszAttributes As String) As Long   Type the following procedure: Function Build_SystemDSN(DSN_NAME As String, Db_Path As String)

Dim ret%, Driver$, Attributes$

Driver = &quot;Microsoft Access Driver (*.MDB)&quot; & Chr(0) Attributes = &quot;DSN=&quot; & DSN_NAME & Chr(0) Attributes = Attributes & &quot;Uid=Admin&quot; & Chr(0) & &quot;pwd=&quot; & Chr(0) Attributes = Attributes & &quot;DBQ=&quot; & 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 &quot;DSN Creation Failed&quot; End If

End Function  In the Immediate window, type the following line, and then press ENTER:

? Build_SystemDSN(&quot;My SampleDSN&quot;,&quot;c:\Northwind.mdb&quot;)

 Click Start, point to Settings, and then click Control Panel.</li> In Control Panel, click ODBC Data Sources, ODBC Data Sources (32-bit), or 32bit ODBC.</li> Click the System DSN tab. Note that My SampleDSN has been added to the System Data Sources list.</li></ol>

Additional query words: OfficeKBHowTo inf ACC2002 reviewdocid ACC2007

Keywords: kbdatabase kbdesign kbprogramming kbhowto KB287668

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.