Can I use this approach efficiently?
using(SqlCommand cmd = new SqlCommand("GetSomething", new SqlConnection(Config.ConnectionString))
{
cmd.Connection.Open();
// set up parameters and CommandType to StoredProcedure etc. etc.
cmd.ExecuteNonQuery();
}
My concern is : Will the Dispose method of the SqlCommand (which is calle...
Edit: My problem is not a problem anymore: I have redo my performances tests and I have do a fatal stupid error: I had forget a x1000 to get seconds from milliseconds :/
Sorry for that guys.
For info:
- I do some 1900 updates per second from my PC to the DataBase server on local network.
- 3.200 updates per second if the programs ...
In this sentence:
myCommand.ExecuteReader(CommandBehavior.CloseConnection)
does it close connection in case of exception?
...
What's the best method to pass parameters to SQLCommand? You can do:
cmd.Parameters.Add("@Name", SqlDbType.VarChar, 20).Value = "Bob";
or
cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = "Bob";
or
cmd.Parameters.Add("@Name").Value = "Bob";
It seems like the first one might be somehow "better" either performance-wise or err...
Hello,
I have a generated DataSet with bunch of tables. In one table I have a custom query that I use to select people that are older than 15 years. I would like to change this query during working program, so that the query will look like 'select * from people where age > 17'. Now it looks like 'select * from people where age > 15'.
A...
I have a SqlCommand object, and I execute its ExecuteNonQuery method. The query fails, but I can't see how to obtain the query to debug it. Could you help me?
Update I am currently using Wireshark (tcpdump) to read the command, but I think that its not the best solution
Update The CommandText property only provides the Stored Procedure...
I have been playing with the demo code from this msdn article by Jeffrey Richter.
I have added a new function to his ApmToCcrAdapters to handle the SqlCommand.BeginExecuteReader. Only it is closing the reader before I can read it.
The following code is used to provide a FromIteratorHandler:
private static IEnumerator<ITask> Asy...
Hi,
Could anyone notice what could be wrong with the following function:
public string Login(string username, string password)
{
string result = "";
string select = "SELECT user_id FROM [user] WHERE username = @username AND password = @password";
SqlConnection conn = new SqlConnection(connectionString);
...
I'm paging data using an ObjectDataSource and I have the following method:
public int GetNumberOfArticles(string employeeIds)
{
System.Data.DataTable dataTable;
System.Data.SqlClient.SqlDataAdapter dataAdapter;
System.Data.SqlClient.SqlCommand command;
int numberOfArticles = 0;
command = new System.Data.SqlClient.S...
I have a custom data type called StudentID, which has an implicit conversion to string.
When I pass a StudentID instance to SqlCommand.Parameters.AddWithValue (as the value) and execute the command, I receive the following error:
"No mapping exists from object type StudentID to a known managed provider native type."
Specifying a type ...
I have a stored procedure that executes much faster from Sql Server Management Studio (2 seconds) than when run with System.Data.SqlClient.SqlCommand (times out after 2 minutes).
What could be the reason for this?
Details:
In Sql Server Management Studio this runs in 2 seconds (on production database):
EXEC sp_Stat
@DepartmentID...
Is there any difference between SqlCommand.CommandTimeout and SqlConnection.ConnectionTimeout in .NET?
...
I have a dal layer with lots of methods, all of them call stored procedures, some return lists (so with a use of SqlDataReader), others only a specific value.
I have a helper method that creates the SqlCommand:
protected SqlCommand CreateSprocCommand(string name, bool includeReturn, SqlDbType returnType)
{
SqlConnectio...
I want to load a list of records given a possibly lengthy list of usernames (anywhere from one to thousands of usernames).
Disregard how the name(s) are chosen, and assume they cannot be determined from any existing data in the database. This applies to SQL Server 2005.
I specifically want to avoid using a single select statement with ...
I have the following code that uses the SqlClient.ExecuteScalar method to return an ID from a table.
using (var conn = new SqlConnection(connectionString))
using (var cmdContrib = new SqlCommand("SELECT ContributorId FROM Contributor WHERE Code='" + folderSystem.ContributorCode + "'", conn))
{
conn.Open();
var contribId = cmdC...
Hi all,
I have an application that is receiving a high volume of data that I want to store in a database. My current strategy is to fire off an asynchronous call (BeginExecuteNonQuery) with each record when it's ready. I'm using the asynchronous call to ensure that the rest of the application runs smoothly.
The problem I have is that...
The below piece of code that throws the following exception..
Error Message:
Object reference not set to an
instance of an object. Stack Trace:
at
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior,
Boolean returnStream) at
System.Data.SqlClient.SqlCommand.ExecuteNonQ...
Hi,
I feel like I should be able to find the answer to this question but for the life of me I can't seem to get the information I'm looking for.
We have some lists of data being fetched in our application via a SqlCommand performing a SELECT query on a SqlServer database. We do not explicitly setup a transaction on the SqlCommand, ins...
The environment I am using is C# 3.5, ado.net, sqlserver 2005.
using System.Data; using System.Data.SqlClient;
I am using a SqlCommand cmd.Parameters of SqlDbType.DateTime to create a record in the database.
Seconds are not being stored in the database. The field in the db is of type datetime.
Do I need to do something special to ...
Currently what i am doing for transaction management is:
Connection connection = getConnection();
connection.setAutoCommit(false);
updateTableX ( connection, ... );
updateTableY ( connection, ... );
connection.commit();
closeConnection();
I would like to know, if it is possible to avoid closing the connection in my 'updateTableX' meth...