no need of deployment
Hi there,
YOu can make the program automatically create the ODBC in form load ( after checking if the ODBC exists or not).
Here is the function to check if the ODBC is there
Public Sub FetchDSNs()
Dim ReturnValue As Short
Dim DSNName As String
Dim DriverName As String
Dim DSNNameLen As Short
Dim DriverNameLen As Short
Dim SQLEnv As Integer
If SQLAllocEnv(SQLEnv) <> -1 Then
Do Until ReturnValue <> SQL_SUCCESS
DSNName = Space(1024)
DriverName = Space(1024)
ReturnValue = SQLDataSources(SQLEnv, SQL_FETCH_NEXT, DSNName, 1024, DSNNameLen, DriverName, 1024, DriverNameLen)
DSNName = Microsoft.VisualBasic.Left(DSNName, DSNNameLen)
DriverName = Microsoft.VisualBasic.Left(DriverName, DriverNameLen)
If DSNName <> Space(DSNNameLen) Then
' In here you check for the name of the ODBC that need to be created
End If
Loop
End If
End Sub
And here is the code to create ODBC
Public Sub CreateSystemDSN()
Dim ReturnValue As Integer
Dim Driver As String
Dim Attributes As String
Driver = "Microsoft Access Driver(*.mdb)" 'replace with SQL Server if you want to create dsn for sql server .....ako pravis za sql server samo smeni sql server namesto mad(*.mdb)
Attributes = "DESCRIPTION=NewDSNAccess" & Chr(0)
Attributes = Attributes & "DSN=DSN_TEMP2" & Chr(0)
Attributes = Attributes & "DATABASE=C:\myDB.mdb" & Chr(0)
Attributes = Attributes & "PWD=abc" & Chr(0)
ReturnValue = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, "Microsoft Access Driver (*.mdb)", Attributes)
If ReturnValue <> 0 Then
MsgBox("DSN Created")
Else
MsgBox("Create Failed")
End If
End Sub
Hope that this can help you