且构网

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

如何在Windows窗体应用程序中连接到远程服务器?

更新时间:2023-11-07 20:44:34

您只需更改连接字符串即可。但是你应该先把它放在你的app.config中,这样你就不必在每次需要更改它时重新编译。



参见 http://msdn.microsoft.com/en-us/library/ms184658(v = VS.100 ).aspx [ ^ ]



连接字符串只需要指向新服务器。请参见 http://www.connectionstrings.com/ [ ^ ]示例。
You just have to change your connection string. But you should put it in your app.config first so you don't have to recompile every time you need to change it.

See http://msdn.microsoft.com/en-us/library/ms184658(v=vs.100).aspx[^]

You connection string just has to point to the new server. See http://www.connectionstrings.com/[^] for examples.


1)将您的服务器与Sql server management studio连接。



2)如果未在服务器上创建数据库,则首先在那里创建数据库。你可以用两种方式做到这一点。通过从本地计算机创建数据库备份并将其还原到服务器。



3)在web.config中只需用服务器或域的live ip替换你的连接字符串名称。你还必须在web.config中提供用户名和密码。
1) Connect your server with Sql server management studio.

2) If database is not created at your server, then first create database there. you can do it with two ways. by creating backup of database from your local machine and restore it to the server.

3)in web.config just replace your connection string with live ip of server or domain name. you have to also provide username and password in web.config.


SqlConnection con = new SqlConnection();

string Constring =Server = Serveranme / sql2008; database = prasiddhi;集成安全性= sspi;




服务器中的
= Serveranme / sql2008或使用ip 192.165.1.1/sql2008





首先使用sql server连接,如果获得连接,则更改连接字符串,如上面的方法
SqlConnection con = new SqlConnection();
string Constring = "Server=Serveranme/sql2008;database=prasiddhi;Integrated security=sspi";


in Server=Serveranme/sql2008 or use ip 192.165.1.1/sql2008


first you connect using sql server ,if getting connection then change your connection string like above method