Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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. Is there a way to do "Test Connection" that would physically establish a connection with the database?

like image 351
dotNET Avatar asked Aug 16 '26 05:08

dotNET


1 Answers

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.

like image 166
JanC Avatar answered Aug 17 '26 18:08

JanC