.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?
Re: .net sqllite throwing exception
Finally figured it out. I should have been using sqlceconnection and sqlcecommand.