6

I've got this project that I wrote in VS2010 as a WinForms project. I'm not writing it in VS2012 as a WPF project. I have a referenced DLL (DailyReport). Inside DailyReport is a method called GetUniqueDates(). It looks like this:

    public List<string> GetUniquesDates()
    {
        var dates = new List<string>();

        const string query = "SELECT date FROM hdd_local_data_v1_2";

        try
        {
            // Exception here  on the connection creation
            using (var connection = new SqlConnection(ConnectionStringFile)) 
            {
                using (var command = new SqlCommand(query, connection))
                {
                    connection.Open();

                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            for (var i = 0; i < reader.FieldCount; i++)
                            {
                                dates.Add(reader.GetValue(i).ToString());
                            }
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {         
            Logger.Error(ex.Message);
        }

        dates.Sort();

        return dates.Distinct().ToList();
    }

The ConnectionStringFile is set in the constructor, and looks like this:

ConnectionStringFile = @"Data Source=C:\hdd_data\Rubicon.hdd;Version=3;New=False;Compress=True;";

Now, in my VS2010 WinForms project, this method worked just fine. However, in my VS2012 WPF project, I get an exception where I noted above. And the exception is:

keyword not supported 'version'.

The database is a SQLite database. I've tried removing the version keyword, but then I'd get the exception:

keyword not supported 'new'.

My question is: Why would the connection work in my WinForms project and not my WPF project? Is there something that changed when dealing with database connections?

Also, please note, this isn't a question about parameterized queries and the like. So, if possible, please those comments to yourself. Thank you.

PiousVenom
  • 6,888
  • 11
  • 47
  • 86
  • 1
    Take a look at this link: http://www.connectionstrings.com/sqlite specifically the last item. – Mark Kram Jan 22 '13 at 16:23
  • @MarkKram: As I stated earlier to a guy who posted that as an answer, and then deleted his question, my database is at the path listed in my connection string. According to that link, the "In-Memory Database" section, I have the correct string. – PiousVenom Jan 22 '13 at 16:25
  • 2
    Don't you need to use actual SQLite classes to access an SQLite in-memory database? I'm pretty sure Microsoft's standard SqlConnection doesn't have a clue on how to connect to one of those... =) – J. Steen Jan 22 '13 at 16:43
  • @J.Steen: You sir, are a genius. I knew I was doing something completely silly. `Data Source` can be the file path, and it works, now that I've changed it from `SqlConnection` to `SQLiteConnection`. Thank you. – PiousVenom Jan 22 '13 at 16:53
  • Feel free to add your solution as your own answer. I know nothing of SQLite, and was just making an educated guess, really. ;) – J. Steen Jan 22 '13 at 17:11

1 Answers1

16

The issue I was having was because I was trying to create a SqlConnection instead of a SQLiteConnection. Making that change solved my issue.

PiousVenom
  • 6,888
  • 11
  • 47
  • 86