Link to home
Start Free TrialLog in
Avatar of Spike UK
Spike UKFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Counting connections to SQL Server through C#

I am trying to determine the number of to a SQL Server database through a website written in C#.
I can correctly determine the number of connections using the following script through MS SQL Server Management Studio:
SELECT  count(spid) as NoOfConnections FROM master.dbo.sysprocesses
(I intend to filter on web connections, but I want to keep it simple for purposes of the question)
This brings back the correct number.
However, when I run it through the website, it always returns just one connection.
I have checked the C# code is correct by querying another set of data on another table- it works fine.
The connection string I am using is:
"Data Source=.\\SQLEXPRESS;Initial Catalog=myDB;Persist Security Info=True;User ID=myid;Password=mypwd"
ASKER CERTIFIED SOLUTION
Avatar of EugeneZ
EugeneZ
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Spike UK

ASKER

Worked perfectly - thanks
Perfect Solution- well explained