11

I am trying to connect to a sqllite db from with a c# application. I have never worked with SQLLite before.

var connectionString = @"data source='C:\TestData\StressData.s3db'";
            connection = new SQLiteConnection(connectionString);
            connection.Open();

When i attempt to open the connection I get the following exception:

System.NotSupportedException: The given path's format is not supported.
   at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)
   at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)

What am I doing wrong?

Thanks..

Nick

Update:

I changed 'data source' to 'DataSource' as suggested to me. Now I receive a new error:

After changing this I get a new error: System.ArgumentException: Data Source cannot be empty. Use :memory: to open an in-memory database at System.Data.SQLite.SQLiteConnection.Open()

Any more suggestions?

1
  • 1
    Try removing the apostrophes within your connection string DataSource parameter: @"DataSource=c:\TestData\StressData.s3db". Commented Jun 14, 2010 at 17:07

2 Answers 2

13

Got it..

"data source=c:\TestData\StressData.s3db; Version=3;"

Looks like the 'Version' attribute is not optional. Interesting that the .NET provider does not show this in the designer property window.

Sign up to request clarification or add additional context in comments.

1 Comment

Using SQLiteConnectionStringBuilder object to build a connection string (instead of hardcoding it as a string) elliminates most of the problems like this (ambiguous parameter names, typos). When it comes to Version attribute, at least my SQLite doesn't need it.
1

According to this, data source should be DataSource

3 Comments

Doh! I think you are right. After changing this I get a new error: System.ArgumentException: Data Source cannot be empty. Use :memory: to open an in-memory database at System.Data.SQLite.SQLiteConnection.Open() I must have to provide an argument?
@Nick, I've never used this, but from the docs it sounds like the argument should be new SQLiteConnection("DataSource=C:\TestData\StressData.s3db"). I don't know why it's not working :\
Actually it looks like it should 'data source'

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.