错误:不支持关键字:"providername". [英] Error: Keyword not supported: 'providername'.

查看:435
本文介绍了错误:不支持关键字:"providername".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用c#在Web应用程序中创建了连接字符串
当我运行应用程序时,导致以下错误:不支持的关键字:"providername".

I have created a connection string in my web app using c#
When i run the app, result this error: Keyword not supported: ''providername''.

con.ConnectionString = " Data Source=; Initial Catalog=; User ID=; Password=; Trusted_Connection=Yes; providerName = System.Data.SqlClient";



我使用哪种类型的连接字符串shuold ??



What type of connection string shuold i use??

推荐答案

我不确定它是否适用于您,但我始终使用以下代码来获取连接字符串.

I am not sure it will works for you or not but I always use following code to get connection string..

protected string ConnectionString
{
get
 {
 return WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
 }
}
using (var connection = new SqlConnection(ConnectionString))
    {
        connection.Open();

         ----------body----------

        connection.close();
    }  



无论您要在Web表单中的何处使用连接字符串,都应使用连接变量.



Wherever you want connection string in web form use connection variable.


这篇关于错误:不支持关键字:"providername".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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