c#中的sql连接字符串 [英] sql connection string in c#

查看:161
本文介绍了c#中的sql连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想连接到c#中的数据库,但是在连接字符串中有错误我该怎么设置它?

这里是我的代码:

i want to connect to a db in c# but have an error in conection string how can i set it??
here is my code:

string str = "Data Source=ADMIN-B19C3BADF;Initial Catalog=bazarkhodro;Integrated Security=True";
           Qconnection.ConnectionString = str;

推荐答案

你可以得到连接字符串按照以下方式...

1.在你的桌面上创建test.udl文件。

2.打开该文件

3.选择你的服务器名称

4.选择你的数据库

5。点击测试连接(如果成功)

6.点击完成。

7.用wordpad / notepad打开同一个文件

8。添加用户名和密码(如果你使用服务器authontication)

复制连接字符串并将其配置为你的配置文件

喜欢



you can get connection string in following way also...
1. create test.udl file on ur desktop.
2. open that file
3. select ur sever name
4. select ur database
5. click on test connection (if its succeded)
6. click on finish.
7. open same file with wordpad/ notepad
8. add username and password(if you are using server authontication)
copy the connection string and pest it your config file
like

<connectionStrings>
   <add name="ApplicationServices" connectionString="copy connection string here" 

    />
 </connectionStrings>


我在连接字符串中看不到用户名密码。请参阅本网站

http://www.connectionstrings.com/sql-server-2008 [ ^ ]
I dont see the user name password in the connection string. Refer this website
http://www.connectionstrings.com/sql-server-2008[^]


static string ConStr = "Data Source=ADMIN-B19C3BADF;Initial Catalog=bazarkhodro;Integrated Security=True";
SqlConnection con = new SqlConnection(ConStr);


这篇关于c#中的sql连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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