How to always support SqlConnection

How to maintain SqlConnection (or use another component) always (connected) always during the execution of my .Net application?

I need this because my application must detect using this commnad

exec sp_who2 

how many instances of my application are connected to mydatabase to restrict access (license control).

Example

A) my application is made from location1

  • check the number of my applications connected to sql server using exec sp_who2
  • if the number of my applications is <MaxLicencesConnected , then start my application and open sqlconnection

B) my application is made from location2

  • check the number of my applications connected to sql server using exec sp_who2
  • if the number of my applications> = MaxLicencesConnected , close my application

sorry for my English.

early.

+6
c # sqlconnection
source share
4 answers

The connection pool supports the connection:

http://msdn.microsoft.com/en-us/library/8xx3tyca.aspx

+2
source share

Wouldn't it be easier to just have a table in which you add an entry when the program starts and delete it when you exit the program? Constantly maintaining a connection to SQL Server is quite expensive.

Technically, someone can come up with deleting the record and launch a new instance, but obviously, if they do, the first instance will stop working (provided that it checks for its own record every time).

+3
source share

Use connection pool . Set the Maximum Pool Size and the Minimum Pool Size and Join to Connection String.

+1
source share

Myabe you can set the connection object, open it and save it in a global (static) variable. I believe you will also need to set the connection timeout, otherwise it will be automatically closed if it is empty.

To be honest, I don’t think that maintaining an open connection is a good idea because they are expensive.

0
source share

All Articles