Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I need to do something where I create a blank database, and then run commands to generate my schema. I have everything worked out as far as I can tell, but for some reason every time I try to connect I get an error saying "Invalid format for parameter C:\Test\test.db"

Here's the code where I get the problem.
C#
SQLiteConnection.CreateFile(filePath);
               String connectionString = "Data Source=" + filePath+";";
               using (var connection = new SQLiteConnection(filePath))
               {
                   connection.Open();

I have tried it with DataSource or Data Source in the connection string property. I also tried with and without that appended semicolon at the end. The CreateFile works, but then I can't get my connection to open. It throws an exception every time.

Can anyone please help me?
Posted
Updated 16-Apr-11 4:49am
v2
Comments
strogg 16-Apr-11 13:21pm    
you're using 'filepath' to open the connection. I guess u forgot to use connectionString you've created :)
DannyStaten 16-Apr-11 14:51pm    
Wow thanks for the fresh pair of eyes there.

1 solution

You must pass connectionString to the constructor, not the path

using (var connection = new SQLiteConnection(connectionString))

-Robotex
 
Share this answer
 
Comments
DannyStaten 16-Apr-11 14:45pm    
LOL thanks. Count that one up as a brain fart that I just needed a fresh pair of eyes on. Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900