如何给连接字符串键值? [英] How to give connection string as a key value?

查看:142
本文介绍了如何给连接字符串键值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给连接字符串作为重点。
所以我在web.config中写这篇code。

 <添加键=CONNECTSTRING值=数据源= USER-PC;初始目录=数据库名;集成安全性= FALSE;的providerName = System.Data.SqlClient的/&GT ;
  < /的appSettings>

但有错误,它说:

 关键字不支持:的providerName。
说明:执行当前Web请求的执行过程中发生未处理的异常。请查看有关错误的详细信息的堆栈跟踪以及它起源于code。异常详细信息:System.ArgumentException:关键字不支持:的providerName。源错误:28号线:康涅狄格州的SqlConnection;
第29行:CONN =新的SqlConnection(ConfigurationManager.AppSettings [CONNECTSTRING]的ToString());
第30行:
第31行:

我该如何解决呢?


解决方案

 <&的appSettings GT;
<添加键=CONNECTSTRING值=数据源= USER-PC;初始目录=数据库名;集成安全性= FALSE;的providerName =System.Data.SqlClient的/>

单独的的providerName 在你的价值

请注意:有一个在你的价值的错误,之后添加了双qoutation 假;

I want to give connection string as a key. So I write in web.config this code.

    <add key="connectstring" value="Data Source=USER-PC;Initial Catalog=DBName; Integrated Security=False; providerName=System.Data.SqlClient"/>
  </appSettings>

but there is error and it says

Keyword not supported: 'providername'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Keyword not supported: 'providername'.

Source Error:

Line 28:             SqlConnection conn;
Line 29:             conn = new SqlConnection(ConfigurationManager.AppSettings["connectstring"].ToString());
Line 30:                 
Line 31: 

How can I solve it??

解决方案

<appSettings>
<add key="connectstring" value="Data Source=USER-PC;Initial Catalog=DBName; Integrated Security=False;" providerName="System.Data.SqlClient"/>

separate providerName in your value

NOTE: There is an error in your value, add a double qoutation after False;

这篇关于如何给连接字符串键值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆