RE: Duplicate Connections



Here's the basic idea of my code block. Each time I run this, I see two login
events using the SQL Profiler. If I use OLEDB, I only get one. The second
login event is fired when I run the ExecuteReader command. The funning thing
is that even though it creates a second connection to the database, the
actual query runs on the original login connection.

Dim mySql As SqlConnection = New
SqlConnection("SERVER=.;DATABASE=Northwind;USER
ID=sqluser;PASSWORD=password;TRUSTED_CONNECTION=false")
Dim myCmd As SqlCommand = New SqlCommand("spGetAllEmployees", mySql)
myCmd.CommandType = CommandType.StoredProcedure
Dim myDR As SqlDataReader
Try
mySql.Open()
myDR = myCmd.ExecuteReader()
While myDR.Read()
'Do something
End While
Catch ex As Exception

End Try


"John Papa" wrote:

> I just ran a test using the following code and it created a single connection
> and only a single SPID as shown in SQL Server Ent Mgr's Current Activity
> view. What does your code look like?
>
> string sConnString = "Server=MyServer;Database=Northwind;Integrated
> Security=True";
> string sSql = "SELECT CategoryID, CategoryName FROM Categories ORDER BY
> CategoryName";
> using (SqlConnection cn = new SqlConnection(sConnString))
> using (SqlCommand cmd = new SqlCommand(sSql, cn))
> {
> cn.Open();
> using (SqlDataReader rdr = cmd.ExecuteReader())
> while (rdr.Read())
> {
> // do something in here
> }
> }
>
>
>
> // John Papa
> // http://codebetter.com/blogs/john.papa
>
>
>
> "DavidM" wrote:
>
> > I am using the SQLConnection object to establish a connection a SQL Server
> > 2000 PC running on my local PC. Whenever I open the connection I get two
> > loggins on the SQL Server. Does anyone know what is causing this to happen?
.



Relevant Pages

  • RE: Getting Challenged when using SQL connection on .aspx page
    ... What would happen if i removed integrated security=sspi from the connection ... Just want the login token to be passed, ... Have webpage with following connection in the ... I have account to the database on the SQL server. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Using OLEDB from ActiveX DLL
    ... But why use ODBC anyway?). ... It is simply a SQL ... Server Login issue. ... The connection string for OLEDB: ...
    (microsoft.public.vb.general.discussion)
  • Re: SQL.Net connection in VS2005 from local IIS to local SQLExpres
    ... I guess the obvious question would be is there a login defined in SQL Server ... Look at the connection string for the ...
    (microsoft.public.sqlserver.connect)
  • Re: Is there a reliable way to do this?
    ... started when SQL Server starts up? ... right after log-in - there are often login failures reported by ... increased the length of the connection time-out in the connection ... unless the user db's and/or tempdb database is rather large your probably ...
    (microsoft.public.sqlserver.connect)
  • Re: Concurrent database access in SQL 2005 Mobile
    ... Please stick to having an "dummy" connection in Open State. ... SQL CE/Mobile has a background thread that flushes the changes ... they run for long hours and we have not seen memory leaks so far. ... then opens his work forms and it's in ...
    (microsoft.public.sqlserver.ce)