在局域网(LAN)中将C#与SQL Server数据库连接 [英] Connecting C# with SQL Server Database in a Local Area Network (LAN)
问题描述
我创建了一个要在局域网上运行的C#应用程序,以便不同的PC可以安装我的应用程序并访问存储在Server PC上的数据库.现在的要点是,在网络连接方面,我确实是一个新手.现在,我使用以下代码连接到我的数据库:
I have created a C# application that I want to run on a Local Area Network, so that different PCs can install my application and access the database stored on Server PC. Now the point is that i am really a rookie when it comes to Network connectivity. Right now I use this code to connect to my database:
public SqlConnection con = new SqlConnection("Data Source=localhost; Initial Catalog= my_db; Integrated Security= True");
你们可以帮我吗?预先感谢.
Can you guys help me with this? Thanks in Advance.
P.S.我必须在Server PC中安装SQL Server Management Studio吗?
P.S. Do i have to install SQL Server Management Studio in Server PC?
推荐答案
尝试与服务器IP地址一起使用
Try to use with Server IP address
string connectionString = "SERVER=123.123.1.12;" + "UID=xxxxxxx;" + "PWD=xxxxxxx;" + "DATABASE=xxxxxx;" + "Encrypt=FALSE;";
这里的IP地址仅用于演示.请使用您自己的IP地址.我目前拥有此IP地址,并且可以100%正常工作.
Here the IP Address is just for Demo only.Use your own.I'm currently have this, and works 100% fine.
这篇关于在局域网(LAN)中将C#与SQL Server数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!