2

I have recently started learning C#. I am using youtube, MS academy and O'Reallys C# book (big one).

I have tried adding a SQLite database to a simple program - just to see if I can store, alter and read data from it.

I am getting a System.ArgumentException error, telling me, my connection.Open(); has an invalid signs in it.

Here is the code I am using:

    private static void Main(string[] args)
    {
        using (var connection = new SQLiteConnection("Data Source=z:\test.db; Version=3;"))
        {
            using (var command = new SQLiteCommand(connection))
            {
                connection.Open();

I am not sure, what I am doing wrong. I am using the Nuget package called System.Data.SQLite - it is however installed for the whole solution, not just as reference to the Program.cs. Would that matter?

I am using Visual Studio 17 on a 64 bit win 10 computer.

Hope someone knows, where I am failing. :)

Best regards

Brian.

3
  • 1
    z:\ should be z:\\ . Right now, your string would be parsed as Z:<TAB>est.db Commented Aug 1, 2018 at 13:11
  • I found it as you were typing. Thanks anyway. :D Commented Aug 1, 2018 at 13:14
  • You're welcome, happy coding ;-) Commented Aug 1, 2018 at 13:16

1 Answer 1

1

Your string contains a special character \t, which gets interpreted as a TAB.

You should either use a verbatim string by prefixing @ or escape the \t with two backslashes:

@"Data Source=z:\test.db; Version=3;"

or

"Data Source=z:\\test.db; Version=3;"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.