sqlconnection

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

三世轮回 提交于 2019-12-20 07:46:25
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 8 years ago . 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

How to write connection string in web.config file and read from it?

杀马特。学长 韩版系。学妹 提交于 2019-12-18 03:32:48
问题 I'm trying to write Connection string to Web.config like this: <connectionStrings> <add name="Dbconnection" connectionString="Server=localhost; Database=OnlineShopping ; Integrated Security=True"/> </connectionStrings > and read from it like this: string strcon = ConfigurationManager.ConnectionStrings["Dbconnection"].ConnectionString; SqlConnection DbConnection = new SqlConnection(strcon); when run the program I get an error because of the null reference. but when I use this code:

Is it better to execute many sql commands with one connection, or reconnect every time?

喜欢而已 提交于 2019-12-17 09:09:48
问题 Here's my test code, which seems to suggest that it's better to connect multiple times instead of connecting just once. Am I doing something wrong? int numIts = 100; Stopwatch sw = new Stopwatch(); sw.Start(); using (SqlConnection connection = new SqlConnection(connectionParameters)) { connection.Open(); for(int i = 0; i < numIts; i++) { SqlCommand command = new SqlCommand(sqlCommandName, connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue(par1Name,

SqlCommand with using statement

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 06:54:02
问题 I saw that in most samples SqlCommand was used like this using (SqlConnection con = new SqlConnection(CNN_STRING)) { using (SqlCommand cmd = new SqlCommand("Select ID,Name From Person", con)) { SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); return ds; } } I know why we are using "using" statement. But SqlCommand doesn't inlcude Close() method, so should we really use it within using statement 回答1: Because it also implements IDisposable. The purpose of

SqlCommand with using statement

拥有回忆 提交于 2019-12-17 06:52:19
问题 I saw that in most samples SqlCommand was used like this using (SqlConnection con = new SqlConnection(CNN_STRING)) { using (SqlCommand cmd = new SqlCommand("Select ID,Name From Person", con)) { SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); return ds; } } I know why we are using "using" statement. But SqlCommand doesn't inlcude Close() method, so should we really use it within using statement 回答1: Because it also implements IDisposable. The purpose of

in a “using” block is a SqlConnection closed on return or exception?

放肆的年华 提交于 2019-12-16 20:15:59
问题 First question: Say I have using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); string storedProc = "GetData"; SqlCommand command = new SqlCommand(storedProc, connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@EmployeeID", employeeID)); return (byte[])command.ExecuteScalar(); } Does the connection get closed? Because technically we never get to the last } as we return before it. Second question: This

Can't make a connection string in c#

江枫思渺然 提交于 2019-12-14 04:01:55
问题 I'm new to C# and don't know much! I have created a local database in C# 2012 and want to make a connection to it. I tested connection with its wizard and it said successfully connected to database. So I copied connection string address to my code but after few seconds of running i have and exception error! I don't know where the problem is! Here is my code: System.Data.SqlClient.SqlConnection myConnection; private void Form1_Load(object sender, EventArgs e) { myConnection = new System.Data

How to create an SqlConnection in C# to point to UDL file

可紊 提交于 2019-12-14 02:19:36
问题 I have a .udl (Universal data link) file in my project. Now I want to create an SQL Connection that should point to this particular file. SqlConnection object expects a connection string, how can we build an SqlConnection using .UDL file? 回答1: From MSDN site: It is possible to supply connection information for an OleDbConnection in a Universal Data Link (UDL) file; however you should avoid doing so. UDL files are not encrypted, and expose connection string information in clear text. Because a

SQLCommand/SQLConnection vs OleDbCommand/OleDbConnection

倖福魔咒の 提交于 2019-12-14 00:55:42
问题 Does it make a difference whether I use SQLCommand / SQLConnection instead of OleDbCommand / OleDbConnection . Do I get any advantages out of that, from a API comfortability, feature, performance or security perspective? Or any other perspective? 回答1: OleDbCommand and OleDbConnection are general. SqlCommand and SqlConnection are specific to SQL Server, and can take advantage of its features. They also expose the features of SQL Server. For instance, you can use them to manipulate XML columns.

The connection was not closed. The connection's current state is open

时光总嘲笑我的痴心妄想 提交于 2019-12-13 17:25:51
问题 I have to try to do a Registration Form using vb.net on ASP.NET . I already have connection with my database and I already have the code. Unfortunately, I received an error message when trying to validate the form: The connection was not closed. The connection's current state is open. Moreover, it did not insert the data in the database. Can someone help me please. Thanks. Imports System.Data Imports System.Configuration Imports System.Data.SqlClient Partial Class Register2 Inherits System