-
Oct 26th, 2021, 02:00 PM
#1
Thread Starter
New Member
[RESOLVED] SQL Connection forget to working
Dear All,
Someone has an idea what might have happened?
I save my project, SQL database connection was worked properly. I could read and write on database.
Now I'm trying to start my project (during the start process the SQL connection state is tested) but it won't start.
Here is the code:
Code:
Imports System.Windows.Forms
Imports System.Data.SqlClient
Module MainModule
Public sql_connection As New SqlConnection("SERVER = 'PTB\MMD'; Database='mmdinv'; user ID='sa'; Password='xxxx'")
Public Sub Build_SQL_Connection_()
sql_connection.Open()
End Sub
Yes, I know it can be solved another way (declare string and new sql connection separately) but it works.
I have a lot of forms that have the same connection in their own Private Class and now they don't work either.
Anybody has an idea what happened?
Error message: System.InvalidOperationException: The ConnectionString property has not been initialized
Thanks
P.
Last edited by peter.lenkei; Oct 26th, 2021 at 02:26 PM.
-
Oct 26th, 2021, 02:42 PM
#2
Re: [RESOLVED] SQL Connection forget to working
Why is this thread marked as resolved? Did you solve this, if so how?
If it hasn't been resolved, I suggest you try exactly what you suggested: Put the connection string into a string variable, then try creating the connection just before you open it. That shouldn't do much of anything, but I think it would be somewhat easier to diagnose the problem that way.
The other thing to try is just to put a breakpoint on the Open statement and see what is in the connection variable. Not quite sure what you'd be looking for, but you should be able to find the connection string, and it probably won't be there (or else why would you get the error?), which might start a different line of investigation.
My usual boring signature: Nothing
-
Oct 26th, 2021, 03:18 PM
#3
Thread Starter
New Member
Re: [RESOLVED] SQL Connection forget to working
Yes, I solved.
Some of my keys on my keyboard have been stuck for a while and probably it copied "sql_connection As New SqlConnection" from the clipboard (I found it copied several times under each other in the code) into a Sub in another Class. This Sub is running at startup before the SQL connection. During the run the variable has been re-declared, but connection string was empty, that's why I got the error "ConnectionString property has not been initialized"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|