請原諒我,如果這很容易,我已經看到類似的帖子,但我是新的C#,並一直在努力,所以任何幫助將不勝感激。連接到Visual Studio 2012中的SQL Server數據庫C#
我試圖連接到Visual Studio 2012中的本地數據庫SQL Server,但到目前爲止沒有運氣。
我從我的本地數據庫的屬性中獲取了我的連接字符串,其圖片位於左側窗格中。
public void connection()
{
string connectionString = "Data Source=(localdb)\v11.0;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False";
SqlConnection con = new SqlConnection(connectionString);
try
{
con.Open();
lblConnectionTest.Text = "Connected successfully";
}
catch (SqlException ex)
{
lblConnectionTest.Text = ex.Message;
}
}
在這一點上,所有我試圖做的是建立與數據庫的連接,基本上寫出「連接成功」等,如果它連接。
目前與我有什麼,我收到以下錯誤:
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)
什麼我錯在這裏做什麼?
非常感謝!
嘗試使用服務器的IP,如下所示:IP \ v11.0 –