|
-
May 30th, 2012, 02:24 AM
#1
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.
-
May 30th, 2012, 02:38 AM
#2
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..
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
May 30th, 2012, 02:41 AM
#3
Re: Exception while connecting to Ms Access database
Victor Nijegorodov
-
June 4th, 2012, 02:26 AM
#4
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
}
-
June 4th, 2012, 02:50 AM
#5
Re: Exception while connecting to Ms Access database
 Originally Posted by firoz.raj
please always write code inside the code tags .

Agree!
But note that it makes sense only if you place the formatted "code inside the code tags".
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|