views:

22

answers:

2

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.Data.Odbc.OdbcDataAdapter da = new System.Data.Odbc.OdbcDataAdapter(query, conn);
    da.Fill(dt);
    da.Dispose();
    return dt;
}
+1  A: 

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

Markive
Or if it is suppose to be an ODBC connection, change the connection string.
Jeff O
A: 

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.

DaveB