日期:2014-05-17 浏览次数:20480 次
<add name="access1" connectionString="Provider=Microsoft.Jet.OleDb.4.0;Data Source="/> <add name="access2" connectionString="~/App_Data/#Address.mdb"/>
------解决方案--------------------
private static string _AccessConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.AppDomain.CurrentDomain.BaseDirectory.ToString() + @"\Data\Data.mdb;Jet OLEDB:Database Password=ybllz!@#402719"; /// <summary> /// 执行SQl语句,如果执行成功则返回为真 /// </summary> /// <param name="Sql">一条可执行的SQL语句</param> /// <returns>返回一个布尔值,执行成功返回 true,否则返回false</returns> /// private Boolean ExecSql(string Sql) { OleDbConnection Myconn = new OleDbConnection(); OleDbCommand Mycmd = Myconn.CreateCommand(); Boolean RetVal = false; try { Myconn.ConnectionString = _AccessConnStr; Myconn.Open(); Mycmd.CommandText = Sql; Mycmd.CommandType = System.Data.CommandType.Text; Mycmd.ExecuteNonQuery(); Mycmd.Dispose(); Myconn.Close(); Myconn.Dispose(); RetVal = true; } catch (Exception) { Mycmd.Dispose(); if (Myconn.State == ConnectionState.Open) { Myconn.Close(); } Myconn.Dispose(); } return RetVal; }
------解决方案--------------------
数据库是否存在问题
用字符串连接数据看看
<add name="accessConnStr" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source= |DataDirectory|a.mdb" providerName="System.Data.OleDb"/>
<appSettings>
<add key="ConnString" value="provider=microsoft.jet.oledb.4.0;data source="/>
<add key="dbPath" value="~/App_Data/a.mdb"/>
</appSettings>