I've seen questions on this topic around the web (I really try Google before asking...) but I haven't seen one that works/makes sense for the particular line in my program that is giving an error. Part of my confusion is that a month or so ago this was working fine with no change to the relevant code...
I have data coming in from some sensors that I am storing in an SQL Server CE databasae. I'm debugging the program from a flash drive given that my docs is a network share and CE doesn't like that. The SQL connection routine is almost identical to the routine I always use on a full blown SQL database. The biggest difference is with a local database I've had to add the install path of the program.
That doesn't throw the error. That's happy. In fact there are variables in that database that my program is pulling out nicely. The problem is when I try to read out the variables into a dataset to display a chart. The specific line is:
SQL_Server = System.Configuration.ConfigurationManager.AppSettings("SQL_Server")
SQL_Password = System.Configuration.ConfigurationManager.AppSettings("SQL_Password")
SQL_Con.ConnectionString = "Data Source = " & (System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)) & "\\" & SQL_Server & "; Password = " & SQL_Password
'SQL_Con.ConnectionString = "Data Source = " & SQL_Server & "; Password = " & SQL_Password
Catch ex As Exception
MessageBox.Show("Error while connecting to SQL Server." & ex.Message)
The program throws an illegal characters in path exception on this line. I have thrown a line in elsewhere to put the path in a text box just to see what it's getting and it looks good.
What has me scratching my head is that if the path had illegal characters in it, wouldn't the SQL connection throw that exception first?
Any suggestions would be appreciated.