Exception while connecting to Ms Access database
When I connect to the Ms Access database from my Dot net application(VS 2005), I get an exception "System.IO.FileNotFoundException: Could not load file or assembly 'Interop.ADODB, Version=2.8.0.0". But the application and database is in the network. But for most of the systems it works. This exception is only for a few systems.
The code to connect the database is follows
Void ConnectDatabase()
{
MessageBox.Show("ConnectDatabase")
Dim CnSt As String
Dim Cn As OleDbConnection
Dim Ta As New DataTable
Dim database As ADOStruct
database = New ADOStruct
Dim sProvider As String
sPathFileMitglied = sFilename
Try
sProvider = "Microsoft.Jet.Oledb.4.0"
CnSt = "Provider=" & sProvider & ";Data Source=" & sFilename
Cn = New OleDbConnection(CnSt)
Cmd = Cn.CreateCommand()
' TODO: check, if database is not opened by other user
conn = New ADODB.Connection
conn.Provider = sProvider
conn.ConnectionString = "Data Source = " & sFilename
conn.CursorLocation = CursorLocationEnum.adUseClient
conn.Mode = ConnectModeEnum.adModeReadWrite
conn.Mode = ConnectModeEnum.adModeShareDenyNone
conn.CursorLocation = CursorLocationEnum.adUseServer
conn.Open()
database.conn = conn
ADO_OpenDatabase = database
Catch ex As Exception
ADO_OpenDatabase = Nothing
MessageBox.Show("Exception while opening Database - " & ex.ToString(), "Error Opening Database", MessageBoxButtons.OK, MessageBoxIcon.Error)
frmStart.WriteLog("modADO: ADO_OpenDatabase - Exception" + ex.ToString())
End Try
}
From the from I am calling this method. The control even does not enter this function, I mean the message box is also not displayed. As soon as the function ConnectDatabase() is called, it hits an exception in the caller function in the main form. This looks strange for me as the application works properly for most of the systems in the organization. May be they have some different settings which restricts the connection to database. If some one knows this issue, please reply back. Thanks in advance.
Re: Exception while connecting to Ms Access database
Thank you...
This is much better...
I have also answered you question in your original question here..
Re: Exception while connecting to Ms Access database
Re: Exception while connecting to Ms Access database
please always write code inside the code tags .
Code:
Void ConnectDatabase()
{
MessageBox.Show("ConnectDatabase")
Dim CnSt As String
Dim Cn As OleDbConnection
Dim Ta As New DataTable
Dim database As ADOStruct
database = New ADOStruct
Dim sProvider As String
sPathFileMitglied = sFilename
Try
sProvider = "Microsoft.Jet.Oledb.4.0"
CnSt = "Provider=" & sProvider & ";Data Source=" & sFilename
Cn = New OleDbConnection(CnSt)
Cmd = Cn.CreateCommand()
' TODO: check, if database is not opened by other user
conn = New ADODB.Connection
conn.Provider = sProvider
conn.ConnectionString = "Data Source = " & sFilename
conn.CursorLocation = CursorLocationEnum.adUseClient
conn.Mode = ConnectModeEnum.adModeReadWrite
conn.Mode = ConnectModeEnum.adModeShareDenyNone
conn.CursorLocation = CursorLocationEnum.adUseServer
conn.Open()
database.conn = conn
ADO_OpenDatabase = database
Catch ex As Exception
ADO_OpenDatabase = Nothing
MessageBox.Show("Exception while opening Database - " & ex.ToString(), "Error Opening Database", MessageBoxButtons.OK, MessageBoxIcon.Error)
frmStart.WriteLog("modADO: ADO_OpenDatabase - Exception" + ex.ToString())
End Try
}
:D
Re: Exception while connecting to Ms Access database
Quote:
Originally Posted by
firoz.raj
please always write code inside the code tags .
:D
Agree!
But note that it makes sense only if you place the formatted "code inside the code tags".