Access Database connection string error
So I'm making a website on localhost and I have a database in C:\inetpub\wwwroot\Lollipops\App_Data\lollipopDB.mdb that I need to use on my website but when I try to do a SELECT statement on it, it keeps giving me the error: "System.ArgumentException: Keyword not supported: 'provider'."
This is in my web.config file -
< connectionStrings>
< add name="lollipopDB" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\inetpub\wwwroot\Lollipops\App_Data\lollipopDB.mdb;" providerName="System.Data.OleDb" />
< /connectionStrings>
and the website calls the function PerformSQL which takes the name of a connection 开发者_JAVA技巧string and the sql string to run.
public void PerformSQL(string conn, string sqlStr)
{
sqlConn.ConnectionString = ConfigurationManager.ConnectionStrings[conn].ConnectionString;
sql.CommandText = sqlStr;
sql.Connection = sqlConn; //specify connection string for the command instance
sqlConn.Open();
sql.ExecuteNonQuery();
sqlConn.Close();
}
What's the type of sqlConn?
It needs to be OleDbConnection. Similarly the command needs to be an OleDbCommand.
精彩评论