[英].mdf file does not respond to SqlCommand.ExecuteNonQuery
I have a weird problem with my local database. 我的本地数据库有一个奇怪的问题。 I added it as a .mdf
file, and created 2 tables in it. 我将其添加为.mdf
文件,并在其中创建了2个表。
I tested the connection and the message box states that the connection is working properly. 我测试了连接,消息框指出该连接工作正常。
The problem appears when I try to insert data into that database from my C# application. 当我尝试将数据从C#应用程序插入该数据库时,就会出现问题。 I tried 2 different ways: 我尝试了2种不同的方式:
SqlCommand.ExecuteNonQuery("INSERT INTO ....")
通过使用SqlCommand.ExecuteNonQuery("INSERT INTO ....")
.dbml
file (Linq-to-SQL) datacontext 通过使用.dbml
文件(Linq-to-SQL)datacontext When I try to insert data, no error is thrown, but no data is inserted into the database either. 当我尝试插入数据时,不会引发任何错误,但是也不会向数据库中插入任何数据。 What could be the problem? 可能是什么问题呢?
I'm using C# in VS 2010 and SQL Server 2005 to make my application 我在VS 2010和SQL Server 2005中使用C#制作应用程序
most perceived problems with MDF files tend to boil down to one of: MDF文件的大多数已知问题往往归结为以下问题之一:
Check your connection string, and look in the execution folder (not the project folder), until you are very sure which file is being opened. 请检查您的连接字符串,并期待在执行文件夹(而不是项目文件夹),直到你很肯定被打开的文件。 It should get updated after your work (make sure you dispose the connection etc properly). 工作结束后,它应该会更新(确保正确设置连接等)。
Also: try fetching the data in a new data-context immediately after the insert, so see if it made it in or not. 另外:尝试在插入后立即在新的数据上下文中获取数据,因此请查看是否插入了数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.