1 Attachment(s)
Why am I getting two connection in ENTERPRISE MANAGER
I've got this small project I've started...
Trying to get familiar with MDI forms and creating a database connection.
For some reason I'm getting two connections open when this program runs - which makes no sense. I can see that when I go into ENTERPRISE MANAGER.
Just change the name of the server and name of the database to one that you have on your system.
If anyone has time to look this over I would surely appreciate it...
Re: Why am I getting two connection in ENTERPRISE MANAGER
Because your calling "New" twice. Once in the function and a second time when your Dimming the variable in your ADC form. I dont have 2005 installed but it appears to be the issue. Just do a ...
VB Code:
Dim db As Database
db.EstablishConnect("fps-lap-sz", "funds")
You need to have your EstablishConnect function return the SqlClient.SqlConnection so your only instanciating it in the function.
Re: Why am I getting two connection in ENTERPRISE MANAGER
RD - that does and doesn't make sense :confused:
I set a break at the actual .OPEN - and it only appear at that spot once.
I'm trying to be OO - and learn new .Net syntax - all in one day ;)
Re: Why am I getting two connection in ENTERPRISE MANAGER
Ok, thats how I learned .net. Jumped into a large project without even knowing how to show a form. :D
Since I cant test your code as I only have 2003. But I may be wrong. If you have EM open and connected to your db then that also coulds as a connection.
For reference these are the two sections that I found relevant.
VB Code:
Public Class Database
Public Connection As SqlClient.SqlConnection
Public Function EstablishConnect(ByVal strServer As String, ByVal strDatabase As String)
Connection = New SqlClient.SqlConnection
Connection.ConnectionString = "Persist Security Info=False;Integrated Security=SSPI;database=" & strDatabase _
& ";server=" & strServer & ";Connect Timeout=30"
Connection.Open()
End Function
End Class
VB Code:
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
Dim db As New Database
db.EstablishConnect("fps-lap-sz", "funds")
End Sub
Or am I missing anything?
Re: Why am I getting two connection in ENTERPRISE MANAGER
I thought that EM counted as a connection. Don't run your program, and see if there are any connections.
Re: Why am I getting two connection in ENTERPRISE MANAGER
Yes, as I had posted earlier but we need to know if hes counting the extra EM connection or not.
Re: Why am I getting two connection in ENTERPRISE MANAGER
No - I am not counting the EM connection. EM shows the APP connected to it. To be clear, I actually compiled the .Net mess into an .exe and ran it.
At first, I had the connection call in the child form. First child form got me two connections. Second child form got me three connections. Where is this rogue connection coming from? Must be the OO ooze ;)
The program is not all that big - actually, about 10 lines of code. Am I confusing something in stepping through code in .Net? If I set a break at the .OPEN call in the CLASS and it only stops there once, why would two connections be in the EM list?
Re: Why am I getting two connection in ENTERPRISE MANAGER
You didnt use any wizard gui to create your db connection either? If you just press F11 you can step through your entire program. Step through it and check EM to see where the connection gets created and continue on until you get to the second one.
Re: Why am I getting two connection in ENTERPRISE MANAGER
RD - nope - wizard gui's = serious garbage...
I did F11 through the app - maybe with a fresh mind tomorrow something will click...
Did anyone try to run it yet against their own SQL instance? It's a very small app - not much code at all...
Re: Why am I getting two connection in ENTERPRISE MANAGER
Nope, I only have 2003 installed. Maybe PM jmcilhinney or techgnome.
Re: Why am I getting two connection in ENTERPRISE MANAGER
Sorry to do the evil bump...
If anyone with good .Net debugging skills could tell me why this simple app is creating two connections to the database, I would surely appreciate it.
I set a breakpoint at the .OPEN in the DATABASE CLASS and it only arrives at that spot once, but EM is showing two connections.
I've tested this from a compiled .EXE as well.
When I had the call to the class in the MDI child form it appeared that I got two connections on the first child form, and then a third connection when the second child was open and a fourth when the third child was open.
Seems a rogue initial connection is somehow being created.
Re: Why am I getting two connection in ENTERPRISE MANAGER
Sir szlamany, is this resolved already? When I tried your code it seems I only get one connection (using sp_who and sp_who2)...