Tag: ado.net

Any way to set small timeout (milliseconds) in SQL Server (using ADO.NET)?

The question is in the title… Any way I set a SqlCommand to timeout in 100ms? The documentation says SqlCommand / ADO supports timeouts in full seconds only. Basically, I have a very small insert that should take <30ms. Sometimes SQL decides to be slow and my insert is blocked and can take 1-2 seconds. […]

System.NullReferenceException when published to azure

Hello I have published my website which was forking ok locally from visual studio to Azure and now everytime I try to access the page I am getting the following exception. [NullReferenceException: Object reference not set to an instance of an object.] WebApplication1.Logic.RoleActions.AddUserAndRole() +390 WebApplication1.Global.Application_Start(Object sender, EventArgs e) +47 Because its pointing to Logic.RoleActions and […]

Timeout expired. The timeout period elapsed prior to completion of the operation or the server. The wait operation timed out – strange behavoiur

I know that in SO is lot of this kind of topics, but would like to introduce to my concrete example. When running action from web app (ADO.NET, ASP.NET MVC) getting error: Timeout expired. The timeout period elapsed prior to completion of the operation or the server. The wait operation timed out But from the […]

DataAdapter Update not properly Inserting data into SQL Server?

I have 2 DataTables: 1 that is filled with all the data from a table in my database called Ticket_Report, and a second one that is filled with new tickets. I am searching the Ticket_report datatable for duplicates from the new ticket DataTable (and deleting them). Then I merge the new tickets datatable into the […]

Detecting SQL Server reboot

My c# console app runs on an different machine than my SQL Server 2014. I use ado.net to connect to it. How can I detect if the sql server automatically reboots after installing windows updates? On my client application I use SystemEvents_SessionEnding but this does not help me. I read about connection resiliency, but this […]

How to handle “Could not open a connection to SQL Server” with custom message in vb.net

Is there any way to provide your own message to the user in case SQL Server Database is offline or not accessible while loading a VB.NET form! and yeah I don’t want to use Try/Catch because it will show all type of error that occurs for example: Try catch ex as exception MessageBox.Show(“Not Completed Because […]

C# – Dataset or SQL

I have been looking everywhere and have been unable to find an answer to this question, I am probably looking for the wrong thing but I thought I should try here. When i’m programming I interact with SQL databases using SqlConnection and SqlCommand to connect and run stored procedures. However I have seen other such […]

Is predefined query more efficient than ad-hoc SQL query using ADO.NET?

We have a table CroppedImage which has Id, PosX, PosY, Width, Heigth columns with datatype of tinyint and another column CroppedPicture with datatype of varbinary. Here is ad-hoc way : List<int> GetList = GetTopNecessaryImages(); for(int i = 0; i < 100; i++){ com.CommandText = “select * from CroppedImage where Id=” + GetList[i]; using (SqlDataReader objSqlDtReader […]

I don't know what is wrong with this code

I don’t know what is wrong with this code, but it just jumps to the else part. Can you please help me out? SqlCommand cmd = new SqlCommand(“select * from TB_VH_HW where UserName='” + Txtusername.Text + “‘ and Password='” + txtpassword.Text + “‘”, con); con.Open(); int i = (int)cmd.ExecuteScalar(); if (i == 1) Server.Transfer(“userlogin.aspx”); else […]

Incorrect syntax near the keyword 'USE' error while creating database from Script

I am developing a multi tenant application so I need to create database from code for every new client. I have generated script of my schema from SSMS “Generate Script” utility, then I tried the following: public static void CreateIfNotExist(string path) // the path where the script for creating database is located { var db […]

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