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

How can I load SQL data source from a TextBox in C#?

I am developing a program where I need to make a settings form for my database connection. I stopped at how to set the connection string from textboxes. Here is my code: In the settings form: public string adresa_servera() { …
MichalCh
  • 201
  • 3
  • 15
0
votes
2 answers

Why ConnectionString fails for SqlConnection using MSN example in C#?

I am using the following tutorial example verbatim: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcolumn.aspx The error message is that the connection failed. "Modify it to connect to a Norhtwinf=d database…
user1298925
  • 2,304
  • 7
  • 29
  • 43
-1
votes
2 answers

is it safe to get the java.sql.connection to jsp page form servlet

I have created a servlet called dbConnect(return type Connection). In which i wrote the code to connect to the database. Now I am calling the dbConnect(<%Connection con=dbConnect.getConnection()%>) into the JSP file. Since JSP file will be in the…
-1
votes
1 answer

I can’t connect to my database using SqlConnection

I just try to connect to my database with SqlConnection, but I saw the error... The point is I'm using System.Data.SqlClient, but it looks like it doesn't work somehow... private string ConectionString = "Data Source=.;Initial…
-1
votes
2 answers

How can i modify a sql connection string at runtime?

I query a database as follows: string connString = "Data Source=ServerName;Initial Catalog=AdventureWorks;User id=UserName;Password=Secret;"; SqlConnection conn = new SqlConnection(); SqlCommand cmd = new SqlCommand("select * from Orders",…
Jennifer
  • 31
  • 6
-1
votes
1 answer

foreach loop does not encode and insert all bitmaps into my sqlite DB

My code: private void BTN_Save_Click(object sender, EventArgs e) { string DBpath = @"Data Source=.\StudentDB.db;Version=3;"; Bitmap[] PictureBoxesBitmaps = { FirstPictureBitmap, SecondPictureBitmap, ThirdPictureBitmap…
-1
votes
2 answers

SQL cannot connect through ip address C#

I was wondering if someone could help me with this problem I have? I am not able to connect to my SQL server even though I correctly provided my IDE with the SQL server's port number and my IP address. static SqlConnection connection = new…
Epic
  • 1
  • 4
-1
votes
1 answer

Do we need to set sqlcommand to null after doing sqlcommand.connection.close();

So, I am coding it as below, sqlcommand.connection.close(); sqlcommand = null; Now, Visual Studio is giving me a warning as it is an unnecessary assignment at sqlcommand = null. Kindly suggest.
-1
votes
1 answer

'ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.' - C#

The code: private void btnSave_Click(object sender, EventArgs e) { using (con = new SqlConnection(connectionString)) { SqlCommand cmd; switch (action) …
Richard Johnson
  • 309
  • 4
  • 17
-1
votes
1 answer

use a public sql connection or create a connection where is needed?

in a medium application in asp mvc or windows C# which way is betters: 1- create a public sql connection and use in whole of project? 2- create a new sql connection where is needed? note: 1- in the ado.net or ef. 2- use of transaction usual. thanks…
-1
votes
3 answers

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding

hi I'm getting an error Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. I'm alredy changed the connect timeout = 60000 and in database my procedure is executes in 43sec. so plz give…
-1
votes
1 answer

Microsoft.Data.SqlClient.SqlConnection works in debug/release but fails in installed program

I have a C# program that worked, but after an upgrade to VS 2019 / .NET 4.8, the installed program suddenly started to fail. After trying various downgrades and x86, x64 tests, etc. I finally tried to debug the running code, and the error seems to…
VanteGud
  • 7
  • 2
-1
votes
1 answer

SQL data not showing two columns on site

I've got a DB connection to my SQL Server on Azure. Two columns are showing on the page but not showing the other 2. Columns are company name and further details Company Name is standard business name Further Details stores URLs to more information…
thom4s94
  • 107
  • 1
  • 9
-1
votes
1 answer

C# - How can I do MS SQL Server Connection?

I started programming recently and at the moment I am developing a program with SQL Server 2019 and Visual Studio 2019 in C# that performs simple functions for inserting, deleting and displaying data but I cannot understand how to set up the initial…
st4ticv0id
  • 39
  • 6
-1
votes
1 answer

Connecting with the database using C#

I'm trying to get data from a Database and all time I get the next error: No se controló System.NullReferenceException HResult=-2147467261 Message=Referencia a objeto no establecida como instancia de un objeto. Source=ImeApps StackTrace: …
LuckWallace
  • 113
  • 10