如何使与SQL Server的连接字符串. [英] how to make connection string with sql server.

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

问题描述

我尝试使用app.config与数据库建立连接.

代码是这样的:

 <?  xml    版本  ="    编码  ="  utf-8" ? <  配置 > 
  <   connectionStrings  > 
    <  添加    ="   jsl2connection"  connectionString    RABIN-PC \ SQLEXPRESS; Database = jsl2;"    ="    / > 
  <  /connectionStrings  > 
<  /configuration  >  




但是当我运行程序时,发生了如下错误:

不支持的关键字:"rabin-pc \ sqlexpress; database".

谁能帮我一个忙..
请给我一个主意,以及如何编写正确的连接字符串!或请输入正确的连接代码!在connectionstring属性的开头.

进一步阅读
http://www.connectionstrings.com/ [ ^ ]


尝试一下:


<configuration>
  <connectionstrings>
    <add name="jsl2connection" connectionstring="Data Source=RABIN-PC\SQLEXPRESS;Initial Catalog=jsl2; Integrated Security=True" providername="System.Data.SqlClient" />
  </connectionstrings>
</configuration>



希望对您有所帮助:)




使用还可以使用sqlDataSouce,这样您就可以选择数据库和表,从而可以动态创建连接


i have tried to make connection with database using app.config.

and the code is like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add name="jsl2connection" connectionString="RABIN-PC\SQLEXPRESS;Database=jsl2;"  providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>




but while i run the program , error occured like this:

Keyword not supported: ''rabin-pc\sqlexpress;database''.

can any one help me out ..
please give me and idea how to write correct connection string!!!or please write the correct connection code!!!

解决方案

You''re missing "server=" at the beginning of the connectionstring attribute.

Further Reading
http://www.connectionstrings.com/[^]


try this:


<configuration>
  <connectionstrings>
    <add name="jsl2connection" connectionstring="Data Source=RABIN-PC\SQLEXPRESS;Initial Catalog=jsl2; Integrated Security=True" providername="System.Data.SqlClient" />
  </connectionstrings>
</configuration>



hope this helps :)


hi,

use can also use sqlDataSouce with that u can select Database and table in this way u can create connection dynamically


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

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