我正在編寫一個從API獲取數據的Weatherstation。 這工作正常,但我想將它存儲在數據庫中以繪製一個圖形。 但我的代碼似乎不工作。我試着調試它,它在我想要打開數據庫的行上失敗。它貫穿創建數據庫的行。數據庫連接失敗(System.Data.Sqlclient.SqlException)
這些是發生故障的線路:在控制檯
databaseCon = new SqlConnection(@"Data Source=
(LocalDB)\v10.0;AttachDbFilename=C:\Users\Jeroen
Laptop\Desktop\Eindopdrachten\WeatherStation\Eindopdracht\
Weather.mdf;Integrated Security=True;");
databaseCon.Open();
錯誤消息:
類型 'System.Data.SqlClient.SqlException' 的第一次機會異常發生在System.Data。 DLL
會發生什麼:
我想從API獲取數據並將其存入數據庫,以製作具有溫度,位置和日期的圖表。爲此,我創建了一個數據庫,並且我想與它連接。這是錯誤發生的地方。我從上面得到錯誤。 當我調試該消息顯示幾次(100左右),並繼續運行,而不填寫數據庫。
我希望這裏有人能給我一些更多的信息,或者可以看到我做錯了什麼。
更新:
我試圖存取權限的數據庫
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: 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: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)
我使用Visual Studio 2010和SQL Server 2008中 2012不被我的編程支持時,下面的消息筆記本電腦。
你可以開始給我們介紹一下錯誤消息的一些信息。 – Steve
定義「失敗」。你有什麼跡象表明它不能按預期工作?是否有錯誤訊息? – David
難道不應該是'數據源=(的LocalDB)\ 11.0; .....'('v11.0',而不是'v10.0')使用 –