gpt4 book ai didi

c# - 我遇到以下错误 System.Data.SqlClient.SqlException : in C#

转载 作者:行者123 更新时间:2023-11-29 09:37:46 24 4
gpt4 key购买 nike

我正在尝试制作一个程序,用于在 MySQL 数据库中输入/编辑和删除用户。数据库是外部的。

我曾多次尝试更改 SqlConnection

con = new SqlConnection ("Data Source = ip /; Initial Catalog = u181542750_arsob; Integrated Security = True");

完成CODE PASTEBIN

private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=sql34.main-hosting.eu;Initial Catalog=u181542750_arsob;Integrated Security=True");
con.Open();
cmd = new SqlCommand("INSERT INFO Archers (Nume,Prenume,Varsta,Sex,Categorie,E-mail,Telefon,CNP) VALUES (@Nume,@Prenume,@Varsta,@Sex,@Categorie,@E-mail,@Telefon,@CNP)", con);
cmd.Parameters.AddWithValue("@Nume", textBox1.Text);
cmd.Parameters.AddWithValue("@Prenume", textBox2.Text);
cmd.Parameters.AddWithValue("@Varsta", textBox3.Text);
cmd.Parameters.AddWithValue("@Sex", comboBox1.SelectedItem.ToString());
cmd.Parameters.AddWithValue("@Categorie", comboBox2.SelectedItem.ToString());
cmd.Parameters.AddWithValue("@E-mail", textBox4.Text);
cmd.Parameters.AddWithValue("@Telefon", textBox5.Text);
cmd.Parameters.AddWithValue("@CNP", textBox6.Text);
cmd.ExecuteNonQuery();
}

System.Data.SqlClient.SqlException: 'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)'

Win32Exception: The network path was not found

最佳答案

Ping 查看是否已启动

ping sql34.main-hosting.eu

检查您是否可以访问

telnet 31.220.20.81 1433

如果不能,则需要检查端口是否已关闭、是否有防病毒软件正在阻止、该服务器上未创建集成安全性(Windows 用户)或者它没有访问该数据库的权限。

关于c# - 我遇到以下错误 System.Data.SqlClient.SqlException : in C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57243911/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com