ADO.NET calling T-SQL Stored Procedure causes a SqlTimeoutException

Once I determined that it is the ADO.NET connection at the root of the problem, this thread led me to the answer. Basically connections through Sql Server Management Studio (SSMS) by default have SET ARITHABORT ON. ADO.NET connections do not. Setting ARITHABORT OFF and executing the query directly through SSMS gives me the same slow … Read more

Fill an array (or arraylist) from SqlDataReader

It is possible. In .NET 2.0+, SqlDataReader inherits from DbDataReader, which implements IEnumerable (non-generic one). This means that you can use LINQ: List<string> list = (from IDataRecord r in dataReader select (string)r[“FieldName”] ).ToList(); That said, the loop is still there, it’s just hidden in Enumerable.Select, rather than being explicit in your code.

Update DataSet structure in Visual Studio to match new SQL Database Structure

From the MSDN Forums: If you right-click the TableAdapter in the Dataset Designer and click ‘Configure’ the TableAdapter Configuration Wizard opens where you can reconfigure the main query that defines the schema of your table. This should leave the additional TableAdapter queries (the additional methods) that were added after initial configuration. Of course the additional … Read more

How to save image in database using C# [closed]

Try this method. It should work when field when you want to store image is of type byte. First it creates byte[] for image. Then it saves it to the DB using IDataParameter of type binary. using System.Drawing; using System.Drawing.Imaging; using System.Data; public static void PerisitImage(string path, IDbConnection connection) { using (var command = connection.CreateCommand … Read more

Why does the SqlParameter name/value constructor treat 0 as null?

As stated in the documentation for that constructor: When you specify an Object in the value parameter, the SqlDbType is inferred from the Microsoft .NET Framework type of the Object. Use caution when you use this overload of the SqlParameter constructor to specify integer parameter values. Because this overload takes a value of type Object, … Read more

Refactoring ADO.NET – SqlTransaction vs. TransactionScope

You won’t immediately gain anything by switching your existing code to use TransactionScope. You should use it for future development because of the flexibility it provides. It will make it easier in the future to include things other than ADO.NET calls into a transaction. BTW, in your posted example, the SqlCommand instances should be in … Read more

WHERE IN (array of IDs)

You can’t (unfortunately) do that. A Sql Parameter can only be a single value, so you’d have to do: WHERE buildingID IN (@buildingID1, @buildingID2, @buildingID3…) Which, of course, requires you to know how many building ids there are, or to dynamically construct the query. As a workaround*, I’ve done the following: WHERE buildingID IN (@buildingID) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)