Tag: ado.net

How to use SqlCommand to CREATE DATABASE with parameterized db name?

To put it short. I’ve got two simple helpers: private SqlCommand CreateCommand(string text) { SqlCommand cmd = new SqlCommand(); cmd.Connection = connection; cmd.CommandType = CommandType.Text; cmd.CommandText = text; return cmd; } void SetParameter(SqlCommand cmd, string p, string dbName) { cmd.Parameters.Add(p, SqlDbType.NVarChar); cmd.Parameters[p].Value = dbName; } This executes OK: var cmd = CreateCommand(“CREATE DATABASE Demo “+ […]

Occasionally Getting SqlException: Timeout expired

I have application running on my server. The problem with this application is that daily I am getting nearly 10-20, System.Data.SqlClient.SqlException Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding only one of my SP. Here is my SP, ALTER PROCEDURE [dbo].[Insertorupdatedevicecatalog] (@OS NVARCHAR(50) ,@UniqueID VARCHAR(500) […]

Best way to access a SQL Server database using C# .Net

I am new to .NET and have heard about several different ways of querying a SQL Server databse such as ADO.NET and the entity framework. Can anyone give me some advise about the best way to go for new applications? Thanks for any help or suggestions.

Inserting values into a SQL Server database using ado.net via C#

I have created a simple program to insert values into the table [regist], but I keep getting the error Incorrect syntax near ‘)’ on cmd.ExecuteNonQuery();: private void button1_Click(object sender, EventArgs e) { SqlConnection cn = new SqlConnection(“Data Source=DELL-PC;initial catalog=AdventureWorks2008R2 ; User ID=sa;Password=sqlpass;Integrated Security=SSPI;”); SqlCommand cmd = new SqlCommand(“INSERT INTO dbo.regist (” + ” FirstName, Lastname, […]

connection string to a SQL Server cluster

Could anyone point me or tell me how to write connection string to a SQL Server cluster instance? I want to establish trusted connection to a database (initial catalog) of the specific instance of a SQL Server cluster. I find for quite some time but can not find official answer from Google. I am asking […]

poor performance with sqlparameter

I have a web service, so the handler is called multiple times concurrently all the time. Inside I create SqlConnection and SqlCommand. I have to execute about 7 different commands. Different commands require various parameters, so I just add them once: command.Parameters.Add(new SqlParameter(“@UserID”, userID)); command.Parameters.Add(new SqlParameter(“@AppID”, appID)); command.Parameters.Add(new SqlParameter(“@SID”, SIDInt)); command.Parameters.Add(new SqlParameter(“@Day”, timestamp.Date)); command.Parameters.Add(new SqlParameter(“@TS”, […]

How is SqlException Number assigned

SqlException has the property Number. Then there is this: http://msdn.microsoft.com/en-us/library/cc645603.aspx and this: http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx And it seems to be one or the other QUESTION: How is it decided which? REASON FOR ASKING: I need to catch certain SqlExceptions and decide how to deal with them based on the Number property but I don’t know which list […]

inserting textbox values into database

im a newbie here and would like some advice on C# programming i would like to store values from a textbox into a database. so far, i have the following: string connectionString = @”Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Customers.mdf;Integrated Security=True;User Instance=True”; SqlConnection connection = new SqlConnection(connectionString); connection.Open(); string query = “INSERT INTO ProjectList (ProjectName, BiddingDueDate, Status, ProjectStartDate, ProjectEndDate, AssignedTo, […]

How to log in T-SQL

I’m using ADO.NET to access SQL Server 2005 and would like to be able to log from inside the T-SQL stored procedures that I’m calling. Is that somehow possible? I’m unable to see output from the ‘print’-statement when using ADO.NET and since I want to use logging just for debuging the ideal solution would be […]

In-Out Parameter for SqlCommand

I have the following parameter for SqlCommand. How do I make it to both in and out the paramter value for the Stored Procedure. SqlCommand mySqlCommand = new SqlCommand(“aspInsertZipCode”, mySqlConnection); mySqlCommand.CommandType = CommandType.StoredProcedure; mySqlCommand.Parameters.Add(“@DataRows”, dataStringToProcess.ToString());

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.