[RESOLVED] database connection in VB.NET COM module works only if Design Environme...
When I run the following code with Visual Studio .NET installed on a PC function dbOpen returns TRUE.
When I run the assembly with just the framework, dbOpen returns FALSE.
I can't figure out why. I install the Visual Studio .NET to step through with the debugger to find out what is wrong, and magically the function works again, no changes.
I HAVE to be able to distribute my Product without the design environment. Does anybody have any ideas of what is going on??
When I run the following code with Visual Studio .NET installed on a PC function dbOpen returns TRUE.
When I run the assembly with just the framework, dbOpen returns FALSE.
I can't figure out why. I install the Visual Studio .NET to step through with the debugger to find out what is wrong, and magically the function works again, no changes.
I HAVE to be able to distribute my Product without the design environment. Does anybody have any ideas of what is going on??
VB.NET:
'Constant Declaration
Private Const ODBC_ADD_DSN = 1 ' Add data source
Private Const ODBC_CONFIG_DSN = 2 ' Configure (edit) data source
Private Const ODBC_REMOVE_DSN = 3 ' Remove data source
Private Const vbAPINull As Long = 0& ' NULL Pointer
Private Declare Function SQLConfigDataSource Lib "odbccp32.dll" _
(ByVal hwndParent As Integer, _
ByVal fRequest As Integer, _
ByVal lpszDriver As String, _
ByVal lpszAttributes As String) As Boolean
Private theDBLocation As String
Private database As New System.Data.Odbc.OdbcConnection
Public Function dbOpen(ByVal strLocation As String) As Boolean
On Error GoTo errorhandler
dbOpen = False
theDBLocation = strLocation
Dim strAttributes As String
Dim fileInfo As IO.FileInfo
fileInfo = New IO.FileInfo(theDBLocation)
If (fileInfo.Exists = True) Then
strAttributes = "DSN=AcromagIPACDefDB" & Chr(0) & _
"DBQ=" & theDBLocation & Chr(0)
SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, _
"Microsoft Access Driver (*.mdb)", _
strAttributes)
strAttributes = "MaxBufferSize=2048;FIL=MS Access;" & _
"DSN=AcromagIPACDefDB;" & _
"PageTimeout=5;DriverId=25;" & _
"DBQ=" & theDBLocation
database.ConnectionString = strAttributes
If Not database Is Nothing Then
database.Open()
If (database.State = ConnectionState.Open) Then
dbOpen = True
command.Connection = database
End If
End If
End If
Exit Function
errorhandler:
RaiseEvent ErrorOccurred("dbOpen - " & CStr(Err.Number) & " " & Err.Description)
End Function
Last edited: