如何在Windows窗体应用程序中连接到远程服务器? [英] How to connect to a remote server in windows form application?

查看:136
本文介绍了如何在Windows窗体应用程序中连接到远程服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将我的Web应用程序部署并连接到远程服务器。为了维护db,我在windows窗体中开发了应用程序。它适用于本地主机。现在,我希望这个Windows应用程序连接到远程服务器,怎么做?下面我提交我用于Windows应用程序的代码以连接到本地主机。我还有远程服务器的用户ID和密码。





I have deployed and connected my web application to remote server. To maintain the db I have developed application in windows forms. It works well in local host. Now, I want this windows application to connect to remote server, How to do it? Hereunder I submit the code that I used for windows application to connect to local host. I also have user id and password for remote server.


public partial class NewProductAddition : Form
    {
        SqlConnection con = new SqlConnection();
        string Constring = "Server=localhost;database=prasiddhi;Integrated security=sspi";

推荐答案

您只需更改连接字符串即可。但是你应该先把它放在你的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


这篇关于如何在Windows窗体应用程序中连接到远程服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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