本文介绍了ConnectionString属性尚未初始化错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了MySQL数据库的asp.net web应用程序,具有以下connetcion字符串的web.config:

 <添加名称=techConnectionString的connectionString =服务器= VM-tmysql01;用户ID =用户;数据库=高科技,密码=传的providerName =MySql.Data.MySqlClient />

这是code我用得到的web.config中的连接字符串:

<$p$p><$c$c>System.configuration.configurationmanaget.connectionstrings[\"techConnectionString\"].connectionstring;

由于某种原因,我得到的错误:

And the stack trace is:

[InvalidOperationException: The ConnectionString property has not been initialized.]
   System.Data.SqlClient.SqlConnection.PermissionDemand() +6316916
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +6296606
   System.Data.SqlClient.SqlConnection.Open() +300

I'm able to connect to the DB via the Data Sources in Visual Studio and took the ConnectionString from there.I really need some help with it, is there any problem with my connection string?

解决方案

The problem wasn't with the connetion string, it was with the c# code trying to reach it from the web.config file.

i was trying to use:

System.Configuration.ConfigurationManager.ConnectionStrings["techConnectionString"].ConnectionString;

But i needed to use:

System.Web.Configuration.WebConfigurationManager.ConnectionStrings["techConnectionString"].ConnectionString;

这篇关于ConnectionString属性尚未初始化错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 07:21
查看更多