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
-2
votes
2 answers

ASP.NET Core UI App with separate data .dll

I'm in the process of moving the UI side of an application to the new ASP.NET Core MVC structure. Unfortunately, I still need to reference a data layer which is built in the prior-generation ASP.NET framework. This data .dll has the appropriate…
rcastagna
  • 185
  • 2
  • 14
-2
votes
2 answers

Trapping and throwing errors when using ExecuteNonQueryAsync which returns Task

When I do the following, I get a warning that not all code paths return a value if the catch block doesn't return an int; when that catch block returns an int, the capturedException test for null becomes unreachable unless it is placed inside a…
Tim
  • 8,669
  • 31
  • 105
  • 183
-2
votes
1 answer

Connecting to MSSQL Server via remote client with c#

Well, after doing some research i created a database in MSSql server (2014) and can get a connection via sqlconnection with client, by using: SqlConnection cn = new SqlConnection("user id = myUSER; password=myPASSWORD;server=mySERVER;…
RAZ
  • 55
  • 8
-2
votes
1 answer

Connect to an MDF Database

In Visual Studio Form, Im creating a c# application. Im an trying to add data entered into a register form and save it into the MDF Database file i cretased with tables. But i cant connect to the database, Any Help? My Register Button Code when its…
Rajan
  • 21
  • 5
-2
votes
2 answers

using variables in sql connection in php

I use this code for connecting to sql in PHP: public function ffff(){ $connection = new mysql(); $connection->connect('127.0.0.1','root','','miscfb'); } but I want to use a variable instead of 'miscfb'. for example: $db='miscfb'; and the…
-3
votes
3 answers

C# How to connect the local database (access)

I have a question about C#. I wrote a function using ASP.net, when the user clicks the button, it should call this function and insert the sql to the local database. However, I don't know why it is not working. Can anyone help me? My local database…
Dickson Lee
  • 3
  • 1
  • 5
-3
votes
1 answer

Handeling passing of Sql connection used in multiple classes

I am using a Sql-connection to create a temporary table and perform DML operations on it. The temporary table act as a staging area, for preparation of data to be loaded into a data warehouse. I am using a using statement, to properly dispose of the…
Mads
  • 17
  • 1
  • 6
-3
votes
1 answer

Unable to make SQL Client Connection tp SQL Server

I'm using Xamarin to connect to SQL Server while making a mobile application. The application runs on iOS. I am using sql client to establish a connection with the server, but I'm running into weird errors and have exhausted most of my…
izzykk
  • 31
  • 6
-3
votes
1 answer

Closing a null sql connection

I have a question about closing an opened connection to a database in C#. Let's say we abandon the "using" method and use a try/catch/finally block to open and close the connection. try { connection = new SqlConnection(); …
-3
votes
1 answer

Upgrading Database .mdf File Visual 2013 to 2017 SQL Compatible Connection Error?

The Data Source value in the connection string specifies an instance of SQL Server that is not installed. To resolve this issue, you can either choose to install the matching instance of SQL Server or modify the Data Source value in the connection…
-3
votes
1 answer

i have two asp c# pages the first pages uses insert to sql the other will be update

I have two asp c# pages, that are linked together, it is composed of two forms connected to each other. example i'm done with first page so when i click next page (continue to next page) those values that i have entered in the first page will be…
-3
votes
1 answer

C# Create SqlConnection instance with Connection String

I tried to create SqlConnection object with connection string such as SqlConnection con = new SqlConnection("Connection string"); However, when the program runs, exception happens, and the exception says the keyword, port, is not supported. So I…
user3839421
  • 1
  • 1
  • 1
-3
votes
1 answer

How to pass parameters to SqlDataAdapter

I have a Vb.net program that queries a database to get a bunch of records. I can't quite figure out how to pass parameters. below is my code: Dim connectionString As String Dim sqlCnn As SqlConnection Dim sqlCmd As SqlCommand Dim sql…
Shmewnix
  • 1,553
  • 10
  • 32
  • 66
-4
votes
1 answer

Can a static SqlDBConnection cause a thread to get another thread's result set?

While trying to debug an issue with an ASP.NET project, a coworker noticed that a method was instantiating a static SqlConnection. If multiple threads are using that same SqlConnection concurrently, is it possible for one thread's SqlCommand to…
mbeckish
  • 10,485
  • 5
  • 30
  • 55
-4
votes
4 answers

Code Snippet Improvement for database call in .NET

Can I get a list of issues with the code below, and fixes? string ProgramID = HttpContext.Current.Session[CommonFunctions.myNGconnectSessionVars.ProgramId].ToString(); SqlConnection con = new…
Mike Flynn
  • 22,342
  • 54
  • 182
  • 341
1 2 3
72
73