Home All Groups Group Topic Archive Search About

Create Access ODBC DSN ?

Author
26 Jan 2006 1:41 PM
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.

Author
26 Jan 2006 1:55 PM
Carlos J. Quintero [VB MVP]
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



Show quoteHide quote
"Tull Clancey" <tull.clan***@btopenworld.com> escribió en el mensaje
news:drajio$if9$1@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.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?
>
> Cheers,
> Tull.
>
Author
26 Jan 2006 5:40 PM
Paul Clement
On Thu, 26 Jan 2006 13:41:44 +0000 (UTC), "Tull Clancey" <tull.clan***@btopenworld.com> wrote:

¤ 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)
Author
26 Jan 2006 7:59 PM
Prashant
' 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