1
Answer

dBase connection Error

roy barlow

roy barlow

16y
3.8k
1

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

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.

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//

 

Answers (1)