sqlconnection

Is there a risk to having SqlConnection object as a property for a single executable?

I've got the design habit to have a SqlConnection object populated by a child form, showing the child form, establishing the SqlConnection object and having the populated object passed back to the parent form where execution continues. .NET 2.0 and up 0 as follows: Parent form: public SqlConnection sqlcon; //should be property but mad...

SqlConnection Singleton

Greetings, I would like to ask if creating Singleton to have only one active connection to db is a good idea. What i would like to do is: 1) I have a wcf service 2) wcf service gets data from db 3) i would like to create a singleton like this to have only one connection to db: private static PersistanceSingleton _Instance; public st...

How can maintain a SqlConnection open always

How can maintain a SqlConnection (or using another component) open (connected) always during the execution of my .Net app? I need this because my app needs to detect using this commnad exec sp_who2 how many instances of my app are connected to mydatabase, to restrict the access (license control). example A) my app executed from ...

Does DataAdapter.Fill() close its connection when an Exception is thrown?

Hi, I am using ADO.NET (.NET 1.1) in a legacy app. I know that DataAdapter.Fill() opens and closes connections if the connection hasn't been opened manually before it's given to the DataAdapter. My question: Does it also close the connection if the .Fill() causes an Exception? (due to SQL Server cannot be reached, or whatever). Does it ...

Window Workflow database connections

I'm using Windows Workflow with SqlWorkflowPersistenceService. I initialize SqlWorkflowPersistenceService with a connection string and everything works fine. Using the Activity Monitor in SQL Server Management Studio, I can see that the SqlWorkflowPersistenceService executes stored procedures in the database. When I stop my Windows ser...

how to get the sql connection

FS_Setting is a VB class which has all the details of the connections ie: Public Class FS_Setting Public Function Get_RS_Connection() As SqlConnection Try Get_RS_Connection = New SqlConnection("Data Source=***********;User ID=sa;Password=*****;database=*********") Catch ex As System.E...

problem withAsync SqlComman

I have problem with Timeout, when I run a command through app, a timeout exception is thrown, but when I run it directly in sql there is no timeout exception! my SP take about 11 min when I run it directly. for solving this issue, I found below code here, but It doesn't work properly! Immediately after beginExecute, IAsyncResult.iscompl...

Test sql connection without throwing exception

To test if i can connect to my database, I execute the following code : using (SqlConnection connection = new SqlConnection(myConnectionString)) { try { connection.Open(); canConnect = true; } catch (SqlException) { } } This works except it throws an exception if the connection failed. Is there any other way to...

If we cannot retrieve output parameters until SqlDataReader is closed, then why...?

1) While the SqlDataReader is being used, the associated SqlConnection is busy serving the SqlDataReader, and no other operations can be performed on the SqlConnection other than closing it. This is the case until the Close method of the SqlDataReader is called. For example, you cannot retrieve output parameters until after you call ...

Is closing/disposing an SqlDataReader needed if you are already closing the SqlConnection?

I noticed This question, but my question is a bit more specific. Is there any advantage to using using (SqlConnection conn = new SqlConnection(conStr)) { using (SqlCommand command = new SqlCommand()) { // dostuff } } instead of using (SqlConnection conn = new SqlConnection(conStr)) { SqlCommand command =...

CommandBuilder and SqlTransaction to insert/update a row

I can get this to work, but I feel as though I'm not doing it properly. The first time this runs, it works as intended, and a new row is inserted where "thisField" contains "doesntExist" However, if I run it a subsequent time, I get a run-time error that I can't insert a duplicate key as it violate the primary key "thisField". static...

how to close a sqlconnection in asp.net

Hi guys, i would like to know if there's something wrong in this asp.net code: mydatareader = mycmd.executeReader() if myDataReader.HasRow then // Do something end if myConnection.Close() If i avoid to call a "MyDataReader.Close()" does the connection close anyway ? I ask this because i'm assuming that if call a "MyConn.Close" ...

Passing around a SqlConnection

I have created a TransactionScope and within the scope various items are created and updated in the database. During this process I make a lot of calls to the database. Originally I opened a SqlConnection in the beginning of the TransactionScope and passed it around to any function that made a DB call then I closed the connection after a...

Under what circumstances is an SqlConnection automatically enlisted in an ambient TransactionScope Transaction?

What does it mean for an SqlConnection to be "enlisted" in a transaction? Does it simply mean that commands I execute on the connection will participate in the transaction? If so, under what circumstances is an SqlConnection automatically enlisted in an ambient TransactionScope Transaction? See questions in code comments. My guess to...

Why is my SQL Server query failing?

connect(); $arr = mssql_fetch_assoc(mssql_query("SELECT Applications.ProductName, Applications.ProductVersion, Applications.ProductSize, Applications.Description, Applications.ProductKey, Applications.ProductKeyID, Applications.AutomatedInstaller, Applications.AutomatedInstallerName, Applications.ISO, A...

Remote connection to SQL Server Express fails

I have two computers that share the same Internet IP address. Using one of the computers, I can remotely connect to a SQL Server database on the other. Here is my connection string: SqlConnection connection = new SqlConnection(@"Data Source=192.168.1.101\SQLEXPRESSNI,1433;Network Library=DBMSSOCN;Initial Catalog=FirstDB;Persist Security...

ADO.NET: Can a single SqlConnection execute more than one query at once?

How goes it everybody? Very simple question today. If I give two separate Threads two different SqlCommands. If both SqlCommands use the same SqlConnection, can they execute at the same time? Does SqlConnection block this behavior? Or does something... more interesting happen? (I do believe SqlConnections are pooled by connection strin...

Detecting if the garbage collector was invoked (.Net)

When using SqlConnection, it's important to always close it when used - either by .Close() or placing the SqlConnection in a "using". Unfurtunately, people, including myself, tend to forgot that and this is where the garbage collectors rescues me for a while until i've forgot to close my connections too many times or the number of people...

asp.net sqlcommand not doing as it should - debugging help req.

Hi, This is a really odd situation that I can't seem to work out where the problem lies. I have a simple ASP textbox and button, on clicking the button I have a simple sqlconnection/command routine perform a simple update to a database based on the text value of the textbox. Code: Using myConnection As SqlConnection = New sqlConnect...

Global SqlConnection

I have a Web Service that requires an SqlConnection. There are 5 web methods that use this SqlConnection, but presently they are declared (locally) in each of the methods. Would it be acceptable to make it a global variable in this case? Thanks ...