MS Access Database Connection with VB.NET
-
I am trying to connect my vb.net program to MS Access but nothing seems to be going ok. Whenever I declare my connection object, I get this kind of an error An unhandled exception of type 'System.Security.SecurityException' occurred in system.windows.forms.dll here is the code : This is at the very top ------------------------- Imports System Imports System.Data Imports System.Data.OleDb -------------------------- Dim cnn As OleDbConnection = New OleDbConnection() Dim strConnectionString As String Dim strApp_Path As String strApp_Path = System.IO.Directory.GetCurrentDirectory() strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strApp_Path & "\PIB Hiring System.mdb" cnn.ConnectionString = strConnectionString cnn.Open() my database is currently lying in the bin folder. The problem is it does not seem to like it when I declare my connection. Do I have to add anything to my project. Someone please help me!!!
-
I am trying to connect my vb.net program to MS Access but nothing seems to be going ok. Whenever I declare my connection object, I get this kind of an error An unhandled exception of type 'System.Security.SecurityException' occurred in system.windows.forms.dll here is the code : This is at the very top ------------------------- Imports System Imports System.Data Imports System.Data.OleDb -------------------------- Dim cnn As OleDbConnection = New OleDbConnection() Dim strConnectionString As String Dim strApp_Path As String strApp_Path = System.IO.Directory.GetCurrentDirectory() strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strApp_Path & "\PIB Hiring System.mdb" cnn.ConnectionString = strConnectionString cnn.Open() my database is currently lying in the bin folder. The problem is it does not seem to like it when I declare my connection. Do I have to add anything to my project. Someone please help me!!!
Edza, not sure, as I'd do it differently in C# ( using: OleDbConnection = new OleDBConnection(StrConnectionString) isntead, but have you tried leaving out the "..\", so you get: strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='..\PIB Hiring System.mdb'" Alternatively, drop the "\", and put the MDB in the RELEASE or DEBUG folder (depending obviously on which you are using). strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='PIB Hiring System.mdb'" regards, Pauwl Pauwl
-
I am trying to connect my vb.net program to MS Access but nothing seems to be going ok. Whenever I declare my connection object, I get this kind of an error An unhandled exception of type 'System.Security.SecurityException' occurred in system.windows.forms.dll here is the code : This is at the very top ------------------------- Imports System Imports System.Data Imports System.Data.OleDb -------------------------- Dim cnn As OleDbConnection = New OleDbConnection() Dim strConnectionString As String Dim strApp_Path As String strApp_Path = System.IO.Directory.GetCurrentDirectory() strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strApp_Path & "\PIB Hiring System.mdb" cnn.ConnectionString = strConnectionString cnn.Open() my database is currently lying in the bin folder. The problem is it does not seem to like it when I declare my connection. Do I have to add anything to my project. Someone please help me!!!
I don't think it is related to the database. You're getting a
SecurityException
. You're probably trying to run this code from the network. Currently, the database access code requires Full Trust before it will run, which will only occur if running from the local machine. Copy your project to a local hard disk and try again. -
I don't think it is related to the database. You're getting a
SecurityException
. You're probably trying to run this code from the network. Currently, the database access code requires Full Trust before it will run, which will only occur if running from the local machine. Copy your project to a local hard disk and try again.What you are saying is 100 percent correct, because whenever I open my VB.NET framewok it gives me this kind of an error: "The project location is not fully trusted by the VB.NET runtime. This is either it is a network share or mapped to a network share not on the local machine. If the output path is under the project location your code will not execute as fully trusted and you may receive unexpected security exceptions. Click Ok to ignore and continue. Click cancel to choose a different project location." It runs like a dream from my local disk, just as you said. Thank you Mike, I never thought this error was the cause of all my nightmares. Thank you again mike, you saved 90% of my time.