我使用了MySQL数据库的asp.net web应用程序,具有以下connetcion字符串在web.config:ConnectionString属性尚未初始化错误
<add name="techConnectionString" connectionString="server=vm-tmysql01;User Id=user;database=tech;password=pass" providerName="MySql.Data.MySqlClient"/>
这是我的代码中号使用从web.config中获取连接字符串:
System.configuration.configurationmanaget.connectionstrings["techConnectionString"].connectionstring;
出于某种原因,我得到的错误:
The ConnectionString property has not been initialized. An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
和堆栈跟踪是:
[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
我能够通过数据源连接到数据库在Visual Studio和花的ConnectionString从那里。 我真的需要一些帮助,是否有任何问题与我的连接字符串?
尝试更改为System.configuration.configurationmanagement.connectionstrings [ “techConnectionString”]的ConnectionString; –
另外,请确保
http://social.msdn.microsoft.com/Forums/zh-CN/403a6210-5c8d-4c6c-abda-7d8e138facee/the-connectionstring-property-has-not-been-initialized?forum=adodotnetddataproviders –