Tag: ado.net

How do you deal with transport-level errors in SqlConnection?

Every now and then in a high volume .NET application, you might see this exception when you try to execute a query: System.Data.SqlClient.SqlException: A transport-level error has occurred when sending the request to the server. According to my research, this is something that “just happens” and not much can be done to prevent it. It […]

Is there anything faster than SqlDataReader in .NET?

I need to load one column of strings from table on SqlServer into Array in memory using C#. Is there a faster way than open SqlDataReader and loop through it. Table is large and time is critical. EDIT I am trying to build .dll and use it on server for some operations on database. But […]

What is the purpose of System.Data.SqlClient.SqlParameter.IsNullable?

I’m currently trying to write a simple C# wrapper class for all the stored procedures in a database. While building some parameters in C#, I noticed the property SqlParameter.IsNullable and wondered what this is for. As far as I am aware, it is not possible to declare a stored procedure parameter as NOT NULL and […]

CommandType.Text vs CommandType.StoredProcedure

Is there any benefit to explicitly using the StoredProcedure CommandType as opposed to just using a Text Command? In other words, is cmd = new SqlCommand(“EXEC StoredProc(@p1, @p2)”); cmd.CommandType = CommandType.Text; cmd.Parameters.Add(“@p1”, 1); cmd.Parameters.Add(“@p2”, 2); any worse than cmd = new SqlCommand(“StoredProc”); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(“@p1”, 1); cmd.Parameters.Add(“@p2”, 2); EDIT: Fixed bad copy paste job […]

Limit SQL/LDAP Query to 901 Rows

I have the following LDAP/SQL Query being used in an ADO.NET SSIS Package and I am trying to figure out how to limit the rows to 901: SELECT displayName, cn, extensionAttribute5, streetAddress, telephoneNumber, otherTelephone, info, department, company, givenName, mobile, physicalDeliveryOfficeName, facsimileTelephoneNumber, sn, title, mail FROM ‘LDAP://OU=*****,OU=*****,OU=*****,DC=*****,DC=*****,DC=*****’ WHERE objectCategory = ‘Person’ AND objectClass = ‘User’

Calling a stored procedure results in an incorrectly empty DataTable

I have a functioning stored procedure which returns the correct data when executed manually. There are several rows of data in the output. However, the following code I have is always resulting in no rows of data being added to the DataTable. var commandString = string.Format(@”EXEC MyStoredProcedure {0}”, SomeParameter); var dataTable = new DataTable(); using […]

ADO.NET Insert Min Value into SQL Server 2008 Date column crashes

I’m trying to do the following: using (var tx = sqlConnection.BeginTransaction()) { var command = sqlConnection.CreateCommand(); command.Transaction = tx; command.CommandText = “INSERT INTO TryDate([MyDate]) VALUES(@p0)”; var dateParam = command.CreateParameter(); dateParam.ParameterName = “@p0”; dateParam.DbType = DbType.Date; dateParam.Value = DateTime.MinValue.Date; command.Parameters.Add(dateParam); command.ExecuteNonQuery(); tx.Commit(); } where the table has a SQL Server 2008 Date column. I can insert […]

How to fix SQL connection leaks in this code?

I am getting this error on my website: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached. Description: An unhandled exception occurred during the execution of the current web request. Please review the […]

adding a column to a SQL table in VB using ADO.NET commands

I am interested in a minimal set of instructions that allow me to add a column into an existing table in visual basic using ado.net components. My database is made in sql server. I would greatly appreciate a practical commentary to the code as that works best for me edit 1 Imports System.Data.Sql Imports System.Data.SqlClient […]

Connecting to SQL Server in ASP.NET

I am trying to connect to the SQL Server from Visual Web Developer using asp.net but I am facing some problems If anybody helps in this regard i will be greatful. public partial class _Default : Page { protected void Page_Load(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(“Server=localhost;” + “Database=DB;User ID=aaaa;” + “Password=aaaa”); […]

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