且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用sql server连接客户端?

更新时间:2022-10-25 09:12:28

你只需要改变你的连接字符串指向他们的数据库。请参见 http://www.connectionstrings.com/ [ ^ ]例如。


你想要做什么?



如果您需要连接代码行。选择: -



string str = @data source = DEEPAKSHARMA-PC\SQLEXPRESS ;初始目录=新;集成安全性= true;

SqlConnection con = new SqlConnection(str);

con.Open();

你的代码

con.close();



其中粗体字应该是您的SQL SERVER NAME。您可以执行以下步骤: -



1.打开Sqlserver Management Studio

2.转到文件 - >连接对象资源管理器

3.复制服务器名称

4.用复制的代码替换DEEPAKSHARMA-PC\SQLEXPRESS。



或者如果你有用户名和密码,



写下这段代码: -



 string str = @data source = <   b  >  DEEPAKSHARMA-PC\SQLEXPRESS <   / b  > ;初始目录=新;用户ID =您的ID; password =Your PASSWORD; 
SqlConnection con = new SqlConnection(str);
con.Open();
你的代码
con.close();


Hey friends i am creating simple windows form application and i used local database to configure database in app but now client have sql server database connection and they give me userid and password later so how can my app get that connection \ constring .

help me plz.

You just need to change your connection string to point to their database. See http://www.connectionstrings.com/[^] for examples.


What Exactly you want to do?

If the line of code for connection is all you need. Go for:-

string str = @"data source=DEEPAKSHARMA-PC\SQLEXPRESS;initial catalog=new; integrated security=true";
SqlConnection con = new SqlConnection(str);
con.Open();
"YOUR CODE"
con.close();

Where the words in bold should be your SQL SERVER NAME. You can do following steps:-

1. Open Sqlserver Management Studio
2. Go to File-->Connection Object Explorer
3. Copy SERVER NAME
4. Replace DEEPAKSHARMA-PC\SQLEXPRESS with your copied code.

Or if you have user id and password,

Write this code:-

string str = @"data source=<b>DEEPAKSHARMA-PC\SQLEXPRESS</b>;initial catalog=new; user id="Your ID""; password="Your PASSWORD"";
        SqlConnection con = new SqlConnection(str);
        con.Open();
"YOUR CODE"
        con.close();