ConnectionString 属性尚未初始化,怎么办? 10
我的web.config配置文件中的数据连接是:<appSettings/><!--创建Access数据库连接--><connectionStrings><addkey=...
我的web.config配置文件中的数据连接是:
<appSettings/>
<!--创建Access数据库连接-->
<connectionStrings>
<add key="connstr" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source==|data|data.mdb" />
</connectionStrings>
DB.CS类中的调用是:
public DBconnection()
{
myConnection = new OleDbConnection(ConfigurationManager.AppSettings["constr"]);
myConnection.Open();
}
结果出现了下面得错误提示:
“/SGDH”应用程序中的服务器错误。
--------------------------------------------------------------------
ConnectionString 属性尚未初始化。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.InvalidOperationException: ConnectionString 属性尚未初始化。
源错误:
行 26: //
行 27: myConnection = new OleDbConnection(ConfigurationManager.AppSettings["constr"]);
行 28: myConnection.Open();
行 29: }
行 30: public DBconnection(string Astr)
源文件: e:\三剑客\SGDH\App_Code\DBconnection.cs 行: 28
堆栈跟踪:
[InvalidOperationException: ConnectionString 属性尚未初始化。]
System.Data.OleDb.OleDbConnection.PermissionDemand() +46
System.Data.OleDb.OleDbConnectionFactory.PermissionDemand(DbConnection outerConnection) +22
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +89
System.Data.OleDb.OleDbConnection.Open() +19
DBconnection..ctor() in e:\三剑客\SGDH\App_Code\DBconnection.cs:28
indexlink..ctor() in e:\三剑客\SGDH\indexlink.ascx.cs:16
ASP.indexlink_ascx..ctor() in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\sgdh\68259829\7c24a512\App_Web_indexlink.ascx.cdcab7d2.zwlvzhem.0.cs:0
ASP.default_aspx.__BuildControlIndexlink1() in e:\三剑客\SGDH\Default.aspx:40
ASP.default_aspx.__BuildControlform1() in e:\三剑客\SGDH\Default.aspx:16
ASP.default_aspx.__BuildControlTree(default_aspx __ctrl) in e:\三剑客\SGDH\Default.aspx:1
ASP.default_aspx.FrameworkInitialize() in e:\三剑客\SGDH\Default.aspx.cs:912307
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +40
System.Web.UI.Page.ProcessRequest() +85
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +20
System.Web.UI.Page.ProcessRequest(HttpContext context) +110
ASP.default_aspx.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\sgdh\68259829\7c24a512\App_Web_afglm7kz.12.cs:0
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +317
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +65
--------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.42; ASP.NET 版本:2.0.50727.42
高手指教下啊,急啊,谢谢
哦 是写错了
不过改过后试了,还是不行;
myConnection = new OleDbConnection(ConfigurationManager.ConnectionStrings["connstr"].ConnectionString) 这个也试了,不行啊 .... 展开
<appSettings/>
<!--创建Access数据库连接-->
<connectionStrings>
<add key="connstr" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source==|data|data.mdb" />
</connectionStrings>
DB.CS类中的调用是:
public DBconnection()
{
myConnection = new OleDbConnection(ConfigurationManager.AppSettings["constr"]);
myConnection.Open();
}
结果出现了下面得错误提示:
“/SGDH”应用程序中的服务器错误。
--------------------------------------------------------------------
ConnectionString 属性尚未初始化。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.InvalidOperationException: ConnectionString 属性尚未初始化。
源错误:
行 26: //
行 27: myConnection = new OleDbConnection(ConfigurationManager.AppSettings["constr"]);
行 28: myConnection.Open();
行 29: }
行 30: public DBconnection(string Astr)
源文件: e:\三剑客\SGDH\App_Code\DBconnection.cs 行: 28
堆栈跟踪:
[InvalidOperationException: ConnectionString 属性尚未初始化。]
System.Data.OleDb.OleDbConnection.PermissionDemand() +46
System.Data.OleDb.OleDbConnectionFactory.PermissionDemand(DbConnection outerConnection) +22
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +89
System.Data.OleDb.OleDbConnection.Open() +19
DBconnection..ctor() in e:\三剑客\SGDH\App_Code\DBconnection.cs:28
indexlink..ctor() in e:\三剑客\SGDH\indexlink.ascx.cs:16
ASP.indexlink_ascx..ctor() in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\sgdh\68259829\7c24a512\App_Web_indexlink.ascx.cdcab7d2.zwlvzhem.0.cs:0
ASP.default_aspx.__BuildControlIndexlink1() in e:\三剑客\SGDH\Default.aspx:40
ASP.default_aspx.__BuildControlform1() in e:\三剑客\SGDH\Default.aspx:16
ASP.default_aspx.__BuildControlTree(default_aspx __ctrl) in e:\三剑客\SGDH\Default.aspx:1
ASP.default_aspx.FrameworkInitialize() in e:\三剑客\SGDH\Default.aspx.cs:912307
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +40
System.Web.UI.Page.ProcessRequest() +85
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +20
System.Web.UI.Page.ProcessRequest(HttpContext context) +110
ASP.default_aspx.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\sgdh\68259829\7c24a512\App_Web_afglm7kz.12.cs:0
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +317
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +65
--------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.42; ASP.NET 版本:2.0.50727.42
高手指教下啊,急啊,谢谢
哦 是写错了
不过改过后试了,还是不行;
myConnection = new OleDbConnection(ConfigurationManager.ConnectionStrings["connstr"].ConnectionString) 这个也试了,不行啊 .... 展开
展开全部
是你写错字
<add key="connstr"
ConfigurationManager.AppSettings["constr"]);
constr --- <connstr 少一个n
<add key="connstr"
ConfigurationManager.AppSettings["constr"]);
constr --- <connstr 少一个n
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询