Create Access ODBC DSN ?

  • Thread starter Thread starter Tull Clancey
  • Start date Start date
T

Tull Clancey

Hi all.

I've been searching all over the place for a bit of VB Net code that will
create a DSN for an Access database. I've found examples of creating
connections for SQL, but not Access.

Has anyone done this or acn anyone point me in the right direction?

Cheers,
Tull.
 
They keywords should be documented in the help file of the ODBC Access
driver, but you can always create a DSN manually and then get the
keywords/values from the registry:

For system DSNs:

HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI

At minimum, the DSN for access requires the DBQ=myAccessFile.mdb
keyword/value if I recall correctly.

Notice also that you can skip the creation of a DSN and use a DSN-less
connection, adding the "Driver={Microsoft Access Driver (*.mdb)"
keyword/value. Search the DSN-less concept in Google.


--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com
 
¤ Hi all.
¤
¤ I've been searching all over the place for a bit of VB Net code that will
¤ create a DSN for an Access database. I've found examples of creating
¤ connections for SQL, but not Access.
¤
¤ Has anyone done this or acn anyone point me in the right direction?

I don't really recommend that you use the MS Access ODBC driver (use Jet OLEDB instead), but the
below thread (my second post) should demonstrate how:

http://makeashorterlink.com/?F2555184B


Paul
~~~~
Microsoft MVP (Visual Basic)
 
' Declare this in your Declarations

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

'
-----------------------------------------------------------------------------------
Private Sub ConfigureODBC

Dim sDriver = "Microsoft Access Driver (*.mdb)"
Dim sAttributes As New System.Text.StringBuilder
Const ODBC_ADD_SYS_DSN = 4
Dim intResult As Long

sAttributes.Append("DSN=My DSN Name")
sAttributes.Append(Chr(0))
sAttributes.Append("DBQ=")
sAttributes.Append(strDatabasePath)
sAttributes.Append("\MyDB.mdb")
sAttributes.Append(Chr(0))
sAttributes.Append(Chr(0))

intResult = SQLConfigDataSource(0&, ODBC_ADD_SYS_DSN, sDriver,
sAttributes.ToString)

sAttributes = Nothing
end Sub
 
Back
Top