Please help, I have copied some code to connect to a MSAccess database. However when I try to run it I get a Security Exception message.
Weird thing is, in the IDE I can use database explorer to find, open and test the connection to the database.
The database is stored on a shard network drive and unfortunatley I cannot access my C: drive
using System;
using System.Data.OleDb;
class OleDbTest{
public static void Main()
{
//create the database connection
OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=H:\\Initiatives4.mdb");
//create the command object and store the sql query
OleDbCommand aCommand = new OleDbCommand("select * from tbl_users", aConnection);
try
{
aConnection.Open();
//create the datareader object to connect to table
OleDbDataReader aReader = aCommand.ExecuteReader();
Console.WriteLine("This is the returned data from emp_test table");
//Iterate throuth the database
while(aReader.Read())
{
Console.WriteLine(aReader.GetInt32(0).ToString());
}
//close the reader
aReader.Close();
//close the connection Its important.
aConnection.Close();
}
//Some usual exception handling
catch(OleDbException e)
{
Console.WriteLine("Error: {0}", e.Errors[0].Message);
}
}
}