应用程序配置连接字符串 [英] Application configuration-connection strings
问题描述
你好朋友..
我有一个Windows应用程序,并有其app.config文件,在其中添加了名为"Con"的连接字符串.我正在使用SQL Server 2005企业版和Visual Studio 2008 Professional.
app.config文件如下.
Hi friends..
I have a windows application and have its app.config file in which I added connection string named ''Con''. I am using sql server 2005 enterprise edition and visual studio 2008 professional.
The app.config file is as follows.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="Con" connectionString="Data Source=JASIL;User ID=sa;Initial Catalog=Lab_DB"
providerName="System.Data.OleDb"/>
</connectionStrings>
</configuration>
我用下面的代码来检索连接字符串
Dbcon =新的SqlConnection(ConfigurationManager.ConnectionStrings ["Con"].ConnectionString);
但它导致了错误-未在ConnectionString中指定OLE DB提供程序.一个示例是``Provider = SQLOLEDB;''.
然后我将其更改为
and i used the following code to retrieve the connection string
Dbcon = new SqlConnection(ConfigurationManager.ConnectionStrings["Con"].ConnectionString);
but it caused the error - An OLE DB Provider was not specified in the ConnectionString. An example would be, ''Provider=SQLOLEDB;''.
then i changed it to
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="Con" connectionString="Provider=SQLOLEDB.1;Data Source=JASIL;User ID=sa;Initial Catalog=Lab_DB"
providerName="SQLOLEDB.1"/>
</connectionStrings>
</configuration>
它显示错误-不支持的关键字:"provider".
我不知道这是什么错误..请帮助我...
谢谢.
the it shows the error - Keyword not supported: ''provider''.
I dont know what is the error .. Please help me...
Thank You.
推荐答案
此网站始终可以挽救我的皮肤:
http://www.connectionstrings.com/sql-server-2005#p1
this site always saves my skin:
http://www.connectionstrings.com/sql-server-2005#p1
这篇关于应用程序配置连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!