这工作正常,但我想将它存储在数据库中以绘制图形.
但我的代码似乎不起作用.我尝试调试它,它在我要打开数据库的行上失败了.它贯穿我创建数据库的行.
这些是失败的线:
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.dll中发生了’System.Data.sqlClient.sqlException’类型的第一次机会异常
怎么了:
我想从API中获取数据并将其放入数据库中,以生成包含温度,位置和日期的图表.为此,我创建了一个数据库,我想与它连接.这就是错误发生的地方.我从上面得到了错误.
当我调试该消息显示几次(100左右)并继续运行时,不填充数据库.
我希望这里有人可以给我更多信息,或者看看我做错了什么.
更新:
尝试访问数据库时,我收到以下消息
An unhandled exception of type ‘System.Data.sqlClient.sqlException’
occurred in System.Data.dllAdditional @R_418_4045@ion: 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.)
解决方法
http://blogs.msdn.com/b/sqlexpress/archive/2011/07/12/introducing-localdb-a-better-sql-express.aspx
LocalDb也至少需要.NET 4.02,但不幸的是,注册表中的版本总是v4.0.30319,即使你有早期的.NET
http://blogs.msdn.com/b/sqlexpress/archive/2011/10/27/net-framework-4-now-supports-localdb.aspx
如果可能,只需升级到.NET 4.5
如果使用命名实例而不是v11.0并且程序或服务作为其他用户运行并且该用户实例仍附加到数据库,则也可能存在此问题.不幸的是,数据库可能需要一段时间才能自动分离.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。