开发者

OLEDB connection to Access not working; "Data source name not found and no default driver specified"

开发者 https://www.devze.com 2023-01-08 10:25 出处:网络
I am trying to retreive data from the Access Database from my ASP.Net application. It works when I access one table for an ExecuteScalar.

I am trying to retreive data from the Access Database from my ASP.Net application. It works when I access one table for an ExecuteScalar. but in the following code I get this error; Data source name not found and no default driver specified

private static string GetConnectionString()
{

    string importFolder = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["DataPath"].ToString());
    string fileName = ConfigurationManager.AppSettings["DataFile"].ToString();
    return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + importFolder + fileName; 
}

public DataTable getaddresses(string doorno, string Addsearch)
{

    System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection(GetConnectionString());

    DataTable dt = new DataTable();
    string query = "SELECT * FROM Address_tble";
   System.开发者_如何学JAVAData.Odbc.OdbcDataAdapter da = new System.Data.Odbc.OdbcDataAdapter(query, conn);
    da.Fill(dt);
    da.Dispose();
    return dt;
}


Doesn't it need to be an OLEDBConnection not ODBC? You are using Microsoft.Jet.OLEDB.4.0


Change your code to use the OleDbConnection and OleDbDataAdapter as has been suggested.

Try hard coding the path and filename in or output what the GetConnectionString() function returns. I suspect an incorrect format. Get it working first, then if that is the issue, debug the GetConnectionString() function.

0

精彩评论

暂无评论...
验证码 换一张
取 消