.net sqllite throwing exception
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: .net sqllite throwing exception

  1. #1
    Join Date
    Jan 2010
    Posts
    2

    .net sqllite throwing exception

    I am doing the simple task of opening a connection to my .sdf database. I have done this before in previous projects, but this time my program freezes. I placed a break point where the program gets stuck. conn.open(); shows this:

    'conn.ServerVersion' threw an exception of type 'System.InvalidOperationException'

    Here is my code:

    private int nextID(string table, string columnName) {

    // 1. Create your SQL Connection
    // 2. Create and open a connection object
    int returnvalue;
    using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.territories2ConnectionString))
    {

    // 3. Open the Connection
    conn.Open(); //<--program will not got past this point. It freezes!

    // 4. Create the SQL Command and assign it it a string
    string strSQLCommand = "SELECT MAX(" + columnName + ") FROM " + table;

    // 5. Execute the SQL Command
    SqlCommand command = new SqlCommand(strSQLCommand, conn);

    // 6. Use ExecuteScalar() to return the first result
    returnvalue = (int)command.ExecuteScalar();

    // 7. Close the Connection
    conn.Close();
    }

    // 8. Return the Value plus 1
    returnvalue++;
    return returnvalue;

    }

    I have spent 2 days searching the internet, and have found nothing. I even refered to my past projects, and still nothing.

    Any suggestions?

  2. #2
    Join Date
    Jan 2010
    Posts
    2

    Re: .net sqllite throwing exception

    Finally figured it out. I should have been using sqlceconnection and sqlcecommand.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center