C#和SQL数据连接 [英] C# and SQL data connection

查看:79
本文介绍了C#和SQL数据连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个包含打开和关闭与SQl服务器连接的方法的c#类。我想在项目的其他类中使用这个方法。

I need a c# class that contains methods to open and close connection to SQl server. I want to use this methods in other classes of the project.

推荐答案

有很多选项就像你可以使用Sql Helper Class看到这个 SQL Helper类。

SQL Helper Class Microsoft .NET Utility

以及C# - SQL Helper类
There are so many Options Like You can use Sql Helper Class See this SQL Helper class.
or SQL Helper Class Microsoft .NET Utility
and also C# - SQL Helper Class


你需要的是什么谷歌的能力。



.Net框架包含在 ADO.Net [ ^ ]。

ADO.Net提供了连接各种不同数据库所需的所有类es包括SQL。 (使用System.Data.SQLClient命名空间)。



我建议你阅读一下这个论坛以及如何发布问题的常见问题解答它将为您提供有关如何在此处发布问题以获得最佳响应的指导。
What you "need" is the ability to Google.

The .Net framework has comprised on ADO.Net[^] since version 1.1.
ADO.Net provides all the classes you need to connect with a variety of different database types including SQL. (Which uses the System.Data.SQLClient namespace).

I suggest you have a read on that and also on the FAQ on this forum for how to post questions as it will provide you with guidance on how you aught to approach posting questions here in order to get the best response.


sql连接变得简单您没有重新配置刚刚硬编码的



以下用于Windows身份验证



The sql connection get easy way u didnot reconfigure your just hardcoded the

following for windows authentication

string connection=datasource="servername" intial catalog="databasename" integrated security="true"





sql server认证如







sql server authetication like


string connectiondatasource="servername" intial catalog="databasename" Persistinfo security="true" userid="sa"password="123"







重新配置连接字符串只需使用txt文件或xml

i示例

放置调试文件夹dbpathi.ini文件(crete new txt file save with extension .ini file)








to reconfigure the connection string just use txt file or xml
i example to things
place the debug folder dbpathi.ini file (crete new txt file save with extension .ini file )


datasource="servername" intial catalog="databasename" integrated security="true" <pre lang="SQL">







输入以下连接字符串



到简单代码








enter following connection strings

to the simple code


filestream fs=new file stream();
fs=file.open(appdomain.currentdomain.basedirectory+"Dbpath.ini");

streamreader sa=new stream reader(fs);
string reader=sa.readtoend()

sqlconnection connnctoin=new sqlconection(reader);
conection.open()

=


这篇关于C#和SQL数据连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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