Reputation: 33140
Say I have a connection to a database. After reading some stuff I want to connect to the same database. So I naturally use the first database mysqlconnection.serverstring
Well guess what, the password and username is not included in connect1.ConnectionString. So how can I do so? Is this by design?
Using connect1 As New MySqlConnection(ConnectLocalhost.serverString)
connect1.Open()
bla bla bla
Using connect2 As New MySqlConnection(connect1.ConnectionString) ' this won't work
connect2.Open()
End Using
Upvotes: 0
Views: 98
Reputation: 20330
You need to put Persist Security Info = true in your original connection string otherwise it won't be read back.
Course if you do that you might as well not have a user name and password...
Upvotes: 1
Reputation: 1905
Store your Connection String in your configuration - as It need to be changed outside the code (for example - production vs development).
Write an function that returned a active connection or wrapper object, so you can use:
Using MyHelper.GetConnection() ... End Using
In this way, you can use connection and close it, as the connection pooling save the connection for later use.
Upvotes: 1
Reputation: 1208
Can you not just re-use your original connection? Unless you have explicitly closed it, you should still have access.
Upvotes: 0