如何在c#中使用sql server数据库建立连接 [英] how to make a connection in c# with a sql server data base

查看:188
本文介绍了如何在c#中使用sql server数据库建立连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请我是更大的和你宝贵的建议并帮助我们推广。你的sinscer Mian Sahib jan

解决方案

参考:

使用C#中的ADO.NET连接Windows窗体应用程序 [ ^ ]


  var  connectionString =    Persist Security Info = False; Integrated Security = true; Initial Catalog = Northwind; server =(local); 

// 然后将其用于sqlConnection
var con = new SqlConnection(connectionString);





尝试阅读这个让你知道连接字符串中的基本信息。







你可以也在web配置中设置

< appsettings> 
< add key = myConnectionString value = server = localhost; database = myDb; uid = myUser; password = myPass; />
< / appsettings >

// 然后在代码中调用它

string connStr = ConfigurationSettings.AppSettings( myConnectionString);





make this 作为参考。 。 :)


参考此链接:



http://jubayerdevs.blogspot.hk/2011/03/read-connection-string-from-xml-file.html [< a href =http://jubayerdevs.blogspot.hk/2011/03/read-connection-string-from-xml-file.html\"target =_ blanktitle =New Window> ^ ]

please me are the bigner and your valuable sugistion and help us to promote.your sinscer Mian Sahib jan

解决方案

Refer:
Connecting Windows Form Application With ADO.NET in C#[^]


var connectionString="Persist Security Info=False;Integrated Security=true;Initial Catalog=Northwind;server=(local)";

//then use it for sqlConnection
var con=new SqlConnection(connectionString);



try to read this for you to know the basic in connection string.



you can also set it in web config

<appsettings>
<add key="myConnectionString" value="server=localhost;database=myDb;uid=myUser;password=myPass;" />
</appsettings>

//then call it in code behind

string connStr = ConfigurationSettings.AppSettings("myConnectionString");



make this as reference. . :)


Refereed this link:

http://jubayerdevs.blogspot.hk/2011/03/read-connection-string-from-xml-file.html[^]


这篇关于如何在c#中使用sql server数据库建立连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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