[英]Database connection succeeds for non-existent databases
Looks like SQLite database connection doesn't actually try to open database connection when I call Open()
function. 当我调用Open()
函数时,看起来SQLite数据库连接实际上并没有尝试打开数据库连接。 Here's a simple test: 这是一个简单的测试:
var factory = DbProviderFactories.GetFactory("System.Data.SQLite");
connection = factory.CreateConnection();
connection.ConnectionString = "data source=NonExistentDB.db3";
conn.Open();
The above code does not generate any kind of exception. 上面的代码不会产生任何异常。 Moreover, the connection state is Open
after this. 此外,此后连接状态为Open
。 Is there a way to do "Test Connection" that would physically establish a connection with the database? 有没有办法做“物理上与数据库建立连接的测试连接”?
Change to 改成
connection.ConnectionString = "data source=NonExistentDB.db3;FailIfMissing=True"
Without the last argument, it will simply create a new database if the file is not found. 如果没有最后一个参数,如果找不到该文件,它将只创建一个新数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.