Reputation: 6312
I am trying, from my c# codefile to access an Access Database. If I use the:
SqlConnection connection = new SqlConnection(connectionString)
with the connection string being:
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\testing_dev\sm_development\App_Data\SMWeb.mdb"
I get an error when I try and create a dataset that the word 'provider' is not supported! What am I doing wrong?
Upvotes: 0
Views: 2904
Reputation: 1
if u r trying this in c# please try to write "\" two time in the path for example
"F:\testing_dev\sm_development\App_Data\SMWeb.mdb";
otherwise all okey
Upvotes: -1
Reputation: 1166
Use this for access 2007
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|/My_DB.accdb;Persist Security Info=False;
Upvotes: 1
Reputation: 38335
Put down the SqlConnection and pick up the OleDbConnection:
using System.Data;
using System.Data.OleDb;
using System.Configuration;
public class DataAccess
{
string connectionString = ConfigurationManager.ConnectionStrings["KeyName"].ConnectionString;
public DataSet GetData( string sql, string tableName )
{
using( var conn = new OleDbConnection( connectionString ) )
{
conn.Open();
var da = new OleDbDataAdapter( sql, conn );
var ds = new DataSet();
da.Fill( ds, tableName );
return ds;
}
}
}
Upvotes: 1
Reputation: 415600
The "Sql" in "SqlConnection", "SqlCommand", and generally anything in System.Data.SqlClient refers strictly to Sql Server. MS Access is definitely not Sql Server. Look in the System.Data.OleDb namespace instead.
Upvotes: 4
Reputation: 573
Try this.
OleDbConnection connection = new OleDbConnection();
string connectionString= @"Data Source=F:\testing_dev\sm_development\App_Data\SMWeb.mdb";
OleDbConnection is in the System.Data.OleDb namespace.
Upvotes: 5