I searched for hours on this and found a lot of confusing bad code. If you are trying to create a system DSN for an access database using VB.net 2005, this code worked for me
Imports System.Runtime.InteropServices ' this goes at the top of yor form
'This code supplied by scaleprogrammers.com. Please do not remove this line
'or if you want to remove it you can feel free IF you
'provide a link somewhere on you blog or web site
'that says weighing systems and link to http://www.scaleprogrammers.com
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
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 Integer
Public Function Build_SystemDSN(ByVal DSN_NAME As String, ByVal Db_Path As String) As Boolean
Dim ret As Integer
Dim attributes, driver As String
Driver = "Microsoft Access Driver (*.MDB)" & vbNullChar
Attributes = "DSN=" & DSN_NAME & vbNullChar
Attributes &= "Uid=Admin" & vbNullChar & "pwd=" & vbNullChar
Attributes &= "DBQ=" & Db_Path & vbNullChar
ret = SQLConfigDataSource(0&, ODBC_ADD_SYS_DSN, driver, attributes)
Return ret
End Function
'How to call it
ConnString = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & My.Settings.path ' path to access file
Build_SystemDSN("BERRY", My.Settings.path) 'Berry is the System DSN name
