![](/img/trans.png)
[英]C# - How to connect to my computer's SQL Server from another computer?
[英]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,但它仍然無法正常工作! 我嘗試了Internet上找到的所有解決方案,但是沒有用。
忙碌的貓http://non-98.ucoz.com/Untitled5.jpg
運行程序時,我在另一台計算機上看到了這一點。
您必須將integrated security
從true
更改為false
。 檢查此連接字符串
我認為這是由於服務器的可訪問性造成的,請嘗試集成安全性= False或更新連接字符串
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.