如何使用C#创建客户端服务器应用程序 [英] How to create a client server application using C#

查看:239
本文介绍了如何使用C#创建客户端服务器应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..我是一名学位学生,我正在为我的最后一年项目工作。它是一个连接到远程服务器的应用程序,用于管理在该服务器上创建的某个microsoft sql数据库。所以我已经完成了这个应用程序的所有功能,除了它连接到database \server的部分。我想要的是让用户能够在这个应用程序的设置菜单中指定他们想要连接的服务器的IP地址。然后使用他们的登录凭据登录数据库。我一直在搜索,但一直看到开发人员通过visual studio连接到数据库的视频但我希望我的应用程序的用户可以控制他们想要连接的服务器,因为托管数据库的机器可能会改变未来。我需要一些如何解决这个问题的指导方针。我正在为这个项目使用c#和wpf。谢谢



我尝试过:



使用连接数据库visual studio

hi.. i'm a degree student an i'm working on my final year project. its an app that connects to a remote server in order to manage a certain microsoft sql database created on that server. So i have completed all the functionality for this app except for the part where it connects to the database\server. And what i want is for the user to be able to specify, in the setting menu of this app, the ip address of the server to which they want to connect. And then login to the database using their login credentials. i've searched all over but keep seeing videos where the developer connects to the database through visual studio but i want the user of my app to have control in specifying the server to which they want to connect since the machine hosting the database may change in future. Please i need some guidelines on how to go about this. i'm using c# and wpf for this project. thanks

What I have tried:

connecting to the database using visual studio

推荐答案

好的,所以你的连接字符串需要在代码中修改。这是简单的字符串操作。



最简单的方法是用IP地址或主机名替换字符串中的标签:

OK, so your connection string needs to be modified in code. That's simple string manipulation.

The easiest way to do it is to just replace a tag in the string with the IP address or host name:
    Server={SERVER};Database=myDataBase;User Id=myUsername;
Password=myPassword;




string ipAddress = "192.168.0.1";   // or a resolvable host name
string connString = templateConnString.Replace("{SERVER}", ipAddress);


这篇关于如何使用C#创建客户端服务器应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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