RE: Duplicate Connections
- From: DavidM <DavidM@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 12 Apr 2005 09:09:09 -0700
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?
.
- Follow-Ups:
- Re: Duplicate Connections
- From: Sahil Malik [MVP]
- Re: Duplicate Connections
- References:
- Duplicate Connections
- From: DavidM
- RE: Duplicate Connections
- From: John Papa
- Duplicate Connections
- Prev by Date: Re: DataSet Transactions Help
- Next by Date: Re: Duplicate Connections
- Previous by thread: RE: Duplicate Connections
- Next by thread: Re: Duplicate Connections
- Index(es):
Relevant Pages
|