因此,我想在 Microsoft SQL Management Studio 中创建一个 SQL 数据库并将其连接到 Microsoft Visual Studio。我将数据库链接到 Visual Studio 并且它起作用了。现在,我想打开该连接以使用 Windows 窗体应用程序上的按钮对其进行测试。每次我尝试时,它都会显示“无效指针”,但数据库名称是正确的。我不知道出了什么问题。
我仍然收到无效指针错误...我的实例名称是 DESKTOP-BJSAO6B 但它似乎不起作用...
最佳答案
您需要提供一个正确的连接字符串,例如
string connectionString =
"data source=.\SQLEXPRESS;initial catalog=student;integrated security=True;";
using (SqlConnection connection =
new SqlConnection(connectionString))
{
connection.Open();
MessageBox.Show("You are connected");
}
其中 SQLEXPRESS - 命名您的 MSSQL 实例(可能不同)。更多可以看here
关于c# - Microsoft Visual Studio SQL 服务器连接 - 无效指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40906724/