Skip to content

DBase connection Error

roy barlow

Asked Nov 27, 2007, 4:55 AM EST1 answer
Share
LinkedInX

I am trying to connect to an access dBase on my c:\drive. I've got a class that creates the connection string....

C#
class DBConnection
{
private static string DBString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\myTest_db.mdb";
public static System.Data.OleDb.OleDbConnection GetDBConnection()
{
System.Data.OleDb.OleDbConnection myConnection=new OleDbConnection();
myConnection.ConnectionString = DBString;
return myConnection;
}
Back on my form, I try to open a connection to the dB but I get the following error
Request for the permission of type 'System.Data.OleDb.OleDbPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed

on the line indicated below. Any help appreciated.

Thanks in advance.

TypeScript
private void btnLogin_Click(object sender, EventArgs e)
{
//Create instance of command
System.Data.OleDb.OleDbCommand command = new System.Data.OleDb.OleDbCommand();
string user=userTxt.Text;
string password = passwordTxt.Text;
command.CommandText = "SELECT u.userID FROM myTable AS u WHERE (((u.userName)='" + user + "') AND ((u.password)='" + password + "'));";
command.Connection = DBHelper.GetDBConnection();

command.Connection.Open(); //ERROR HERE//

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    What error are you getting? Catch it using try catch.

    try{
    command.Connection.Open();
    }
    catch (Exception ee)
    {
        MessageBox.Show(ee.tostring());
    }
    0