如何从另一台计算机上的 C# 程序连接到 SQL Server [英] How to connect to SQL Server from a C# program on another computer
问题描述
SqlConnection con = new SqlConnection("server=192.168.0.100,1400;user=Users;password=password;database=Example1;integrated security = true;");
SqlDataAdapter sda = new SqlDataAdapter();
DataTable dbdataset = new DataTable();
BindingSource bsource = new BindingSource();
SqlCommand cmd = new SqlCommand();
public void loaddata()
{
try
{
SqlCommand cmdatabbase = new SqlCommand(" select * from Example1.dbo.Users ;", con);
sda.SelectCommand = cmdatabbase;
sda.Fill(dbdataset);
bsource.DataSource = dbdataset;
dataGridView1.DataSource = bsource;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
这是我在 C# Winforms 应用程序中的代码.在我的电脑上它正在工作,但在另一台电脑上它显示错误(它无法在 datagridview 中加载表).我在防火墙中添加了规则并在 SQL Server 配置管理器中启用了 tcp 但它仍然不起作用!我尝试了在互联网上找到的所有解决方案,但没有奏效.
This is my code in C# Winforms application. On my computer it is working but from another computer it shows error (it can't load table in datagridview). I added rule in firewall and I enable tcp in SQL Server Configuration Manager but it still doesn't work! I tried every solution that found in internet but it didn't work.
一只忙碌的猫 http://non-98.ucoz.com/Untitled5.jpg
我在另一台计算机上运行程序时看到了这一点.
I saw this in another computer when running a program.
推荐答案
您必须将 integrated security
从 true
更改为 false
.检查这个连接字符串
You must change the integrated security
from true
to false
. Check this connection strings
这篇关于如何从另一台计算机上的 C# 程序连接到 SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!