Questions tagged [sqlconnection]

Represents an open connection to a SQL Server database.

SqlConnection is a class in .Net's System.Data.SqlClient library that represents a connection between the local machine and a SQL Server database.

The connection can be configured using its ConnectionString property, and must be opened before use (and closed or disposed after use). ADO.NET also implements pooling for the internal connection used by SqlConnection, so calling Open is relatively cheap.

ADO.NET does not provide thread safety for SqlConnection, nor any of the objects that use it (such as SqlCommand or SqlDataReader) - these objects should be used on the same thread as the SqlConnection, and by only one thread at once.

For more information on SqlConnection, see its MSDN page: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.aspx

1086 questions
0
votes
2 answers

What happens to the state of a sql connection in using block after the exception encountered is re-thrown?

Try xConn.ConnectionString = xConnBuilder.ConnectionString xConn.Open() Throw New Exception("Something") Catch ex As Exception Throw Finally If xConn.State = ConnectionState.Open Then xConn.Close() End If End…
Soham Dasgupta
  • 5,061
  • 24
  • 79
  • 125
0
votes
2 answers

Creating a Class for SqlConnection in ASP.NET and then use in your application?

I'm having to select, update, delete, etc. basically everywhere on my web application and every time I'm having to write something like this: con.Open(); cmd = new SqlCommand("update items set item_cost = @cost, item_retail_value = @retail,…
jorame
  • 2,147
  • 12
  • 41
  • 58
0
votes
1 answer

How to connect to SQL Server database using windows authentication remotely?

I have a simple question, I was granted to a SQL Server database using windows authentication on my local machine, I need to know how to use this access on hosting server as well. For example I am in the middle of writing some C# code that pulls…
user1429595
  • 2,635
  • 9
  • 25
  • 30
0
votes
1 answer

Asp.Net - SqlConnection failed from dll

I've already seen some similar question but none of them has received a valid solution. I've an asp.net web site which reference a dll with some method in order to execute a simple operation on database (CRUD operations). When I need to do some…
bit
  • 934
  • 1
  • 11
  • 32
0
votes
1 answer

VB.Net data source connection error

i am using VS2008 VB.net and sql 2008. I tried to connect a new datasource using Microsoft SQL Server Database File (SqlClient) it gives an error; I tried to connect a new datasource using Microsoft SQL Server (SqlClient) it gives an error;
Wepex
  • 163
  • 4
  • 13
  • 32
0
votes
1 answer

Why might one app connect to SQL backend OK and a second app fail if they share the same connectionstring?

Trying to figure out a SQL connection error 26 in our app. We've got two closely related apps Foo and FooAddIn. Foo is a Winforms app built in VS2010 and runs fine and connects fine to our SQLExpress back end. FooAddIn is an Outlook AddIn which…
hawbsl
  • 15,313
  • 25
  • 73
  • 114
0
votes
0 answers

Entity Framework connectionString with remote server (URL)

This is a WPF app which references an Entity Framework class library. In the App.config of the class library project I have this: