Tag: .net

SqlDateTime.MinValue != DateTime.MinValue, why?

I wonder, why SqlDateTime.MinValue is not the same as DateTime.MinValue?

Bulk Update in C#

For inserting a huge amount of data in a database, I used to collect all the inserting information into a list and convert this list into a DataTable. I then insert that list to a database via SqlBulkCopy. Where I send my generated list LiMyList which contain information of all bulk data which I want […]

How to I serialize a large graph of .NET object into a SQL Server BLOB without creating a large buffer?

We have code like: ms = New IO.MemoryStream bin = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bin.Serialize(ms, largeGraphOfObjects) dataToSaveToDatabase = ms.ToArray() // put dataToSaveToDatabase in a Sql server BLOB But the memory steam allocates a large buffer from the large memory heap that is giving us problems. So how can we stream the data without needing enough free memory […]

What's the best method to pass parameters to SQLCommand?

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 error checking-wise. But I would like to know more definitively.

Failed to update .mdf database because the database is read-only (Windows application)

I’ve created a database windows application using in C#. My application is running successfully on Windows XP, but it doesn’t properly execute on Vista or Windows 7 systems. My application shows a message similar to Failed to update .mdf database because the database is read-only Can anyone give me a solution to this?

Algorithm to avoid SQL injection on MSSQL Server from C# code?

What would be the best way to avoid SQL injection on the C#.net platform. Please post an C# implementation if you have any.

Code to validate SQL Scripts

How can I validate sql scripts before executing them using .net 2.0 and c#? If the sql is not valid I want to return error rows.

A connection was successfully established with the server, but then an error occurred during the pre-login handshake

I am getting following error when i am trying to connect Production DB from Local Environment. I was able to connect Production DB before, but suddenly i am getting following error, any idea? A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 […]

Does End Using close an open SQL Connection

If I wrap a SQLConnection in a Using, should I close it or does the end using handle it? using cn as new system.data.sqlclient.sqlconnection() cn.open ‘{do a bunch of other stuff with commands and datareaders here} cn.close ‘Do I need this? end using

SqlConnection SqlCommand SqlDataReader IDisposable

SqlConnection, SqlCommand and SqlDataReader all implement the IDisposable interface. I read about a best practice to always wrap IDisposables into a using block. So, my common scenario for querying data would look something like this (in greater context of course a mapping tool like linq2sql would be suitable, but lets just assume we want to […]

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