我不断收到无法连接到远程MS Access数据库
InvalidOperationException:ExecuteReader需要一个开放且可用的Connection。该连接的当前状态已关闭。]
这是因为我的连接已关闭。我的连接字符串有什么问题?为什么不开放。
protected void Page_Load(object sender, EventArgs e)
{
// Declaration section
//OleDbConnection objDBConn;
OleDbCommand objCmd;
OleDbDataReader objDR;
//create connection object
System.Data.OleDb.OleDbConnection conn = new
System.Data.OleDb.OleDbConnection();
// Modify the connection string and include any
// additional required properties for your database.
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data source= c:\inetpub\wwwroot\cm485a2\rreAccesscm485a2.mdb";
// Create OleDbCommand object with SQL to execute
objCmd = new OleDbCommand("SELECT * " +
" FROM customers " +
" ORDER BY cust_id", conn);
// Create a DataReader and execute the command
objDR = objCmd.ExecuteReader();
// Copy results from DataReader to DataGrid object
GridView1.DataSource = objDR;
GridView1.DataBind();
//close all objects
conn.Close();
conn.Dispose();
}
尝试连接外的代码。 CS中的“=”之后的“”可能足以使其不起作用(它与其他值一起使用)。在使用它之前,请尝试一个明确的'conn.Open'。有时它会自动打开,有时不会,我不确定这些规则是什么 - 先执行它不会伤害,并且会与'conn.Close'对称(考虑使用'using') – 2011-03-17 16:23:34
此访问分贝似乎并不遥远.... – T30 2014-04-09 08:10:58