DataContext.CreateDatabase()表示,文件已经存在 - 但事实并非如此 [英] DataContext.CreateDatabase() says file already exists - but it doesn't
问题描述
这可能是Windows 7的问题,但调用
This might be a Windows 7 issue, but calling
using (var context = new DataClassesDataContext())
{
if (!context.DatabaseExists())
{
context.CreateDatabase();
}
}
在下面的错误
结果:
Results in the following error:
System.Data.SqlClient.SqlException是
未处理消息=数据库
'C:\Temp\SmallBusinessManager.mdf'
已经存在。选择不同的
数据库名。来源=净的SqlClient
数据提供程序错误码= -2146232060
级= 16 LINENUMBER = 1数= 1801
程序=结果
服务器= \.\ pipe\952FCA9D-B4B6-4C\tsql\query
状态= 3堆栈跟踪:在System.Data.SqlClient.SqlConnection.OnError
(SQLEXCEPTION
例外,布尔breakConnection)
在System.Data.SqlClient.SqlInternalConnection.OnError(SQLEXCEPTION
例外,布尔breakConnection)在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning
()
在System.Data.SqlClient的。 TdsParser.Run(runBehavior
runBehavior,的SqlCommand cmdHandler,
SqlDataReader的数据流,
BulkCopySimpleResultSet
bulkCopyHandler,TdsParserStateObject
stateObj)
在System.Data.SqlClient的。 SqlCommand.RunExecuteNonQueryTds(字符串
方法名,布尔异步)
在System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult
结果,字符串methodName中,布尔
sendToPipe)
在System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
在System.Data.Linq.SqlClient.SqlProvider.ExecuteCommand(字符串
命令)
在System.Data.Linq.SqlClient.SqlProvider .System.Data.Linq.Provider.IProvider.CreateDatabase()在System.Data.Linq.DataContext.CreateDatabase
()
System.Data.SqlClient.SqlException was unhandled Message=Database 'C:\Temp\SmallBusinessManager.mdf' already exists. Choose a different database name. Source=.Net SqlClient Data Provider ErrorCode=-2146232060 Class=16 LineNumber=1 Number=1801 Procedure=""
Server=\.\pipe\952FCA9D-B4B6-4C\tsql\query State=3 StackTrace: at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at System.Data.Linq.SqlClient.SqlProvider.ExecuteCommand(String command) at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.CreateDatabase() at System.Data.Linq.DataContext.CreateDatabase()
不过,我已经删除了数据库文件。可能是什么原因?是真正的文件存在,但不知何故看不见?是与结?
However I've deleted the database files. What could be causing this? Are the files really there but invisible somehow? Something to do with junctions?
推荐答案
抓斗的进程监视器,你就可以看到IO操作的文件,以及他们为什么失败。我发现,这是经常去的问题的根源最好,最快的方法。这是一个很好的工具。
Grab Process Monitor and you'll be able to see the file io operations and why they fail. I find that this is often the best and quickest way to get to the root of the problem. It's an excellent utility.
这篇关于DataContext.CreateDatabase()表示,文件已经存在 - 但事实并非如此的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!