Tag: ado.net

Overflow exception when reading decimal values from SQL Server

I’m wondering whether this is a bug or if I’m going something wrong. I’m loading values with a SqlDataReader from a SQL Server 2008 database but under certain circumstances, it fails to convert the SQL values into .net values. (.NET 4.0) I have traced it down to an test-case which demonstrates the actual problem: Working […]

How do I access SQL Server from Windows 8 apps?

I realize that a local SQL Server instance is not accessible to my Windows 8 app. Instead, I have a SQL Server in Azure. In SQL Server Management Studio, I just change the querystring and interact with the Azure database like any other. How can I reference that database in my Windows 8 app?

EF Code First: Cannot connect to SQL Server

I am trying to create a database using code-first approach. When I am running the following code I am getting the following exception. How can we overcome this? Notes: I have SQL Server 2008 R2 on my system. I am not using any config file. I assumed that it will create database using conventions There […]

Entity Framework mapping of object containing list of same objects

Currently in my code I am doing something like this public class Subject { private List<Subject> _prerequisites; } A subject can have many prerequisites (which are also subjects), and subject can be a prerequisite of many subjects. We were originally using typed datasets to save the data to the database and our tables looked like […]

What isolation level does autocommit transaction use in SQL Server?

When I work with update conflict problem with SNAPSHOT Isolation Level, it seems that autocommit transactions use the isolation level used at last time. Condition: ALLOW_SNAPSHOT_ISOLATION is ON, READ_COMMITTED_SNAPSHOT is OFF Step 1 : Execute update statement without transaction using (var sqlconn = new SqlConnection(“Data source=…”)) using (var sqlcmd = sqlconn.CreateCommand()) { sqlconn.Open(); sqlcmd.CommandText = […]

Getting SqlDataAdapter and SqlCommand confused

I’ve got this calling method: public string RunReportSteps(int _reportKey) { DataTable fStepsTable; fStepsTable = GetStepsTable(“xxx.console.pr_xxx”); return (string)fStepsTable.Rows[1][3]; } It calls this private method: private DataTable GetStepsTable(string procName) { var connectionString = ConfigurationManager.ConnectionStrings[“xxx”].ConnectionString; using(var conn = new SqlConnection(connectionString)) using(var adapt = new SqlDataAdapter()) using(var cmd = new SqlCommand(procName, conn)) { conn.Open(); SqlParameter p = new SqlParameter(“@ReportKey”, […]

Closing SQL-connection but open connections keeps incrementing

I have the following method: public DataSet GetDataSet( string sp, params SqlParameter[] parameters ) { DataSet ds = new DataSet(); using ( SqlConnection conn = new SqlConnection( ConfigurationManager.ConnectionStrings[“myConnectionString”].ConnectionString ) ) { using ( SqlCommand cmd = new SqlCommand() ) { cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = sp; if ( parameters != null ) […]

Possible to view T-SQL syntax of a stored proc-based SqlCommand?

I was wondering if anybody knows of a way to retrieve the actual T-SQL that is to be executed by a SqlCommand object (with a CommandType of StoredProcedure) before it executes… My scenario involves optionally saving DB operations to a file or MSMQ before the command is actually executed. My assumption is that if you […]

How to use SQL Server table hints while using LINQ?

What is the way to use Sql Server’s table hints like “NOLOCK” while using LINQ? For example I can write “SELECT * from employee(NOLOCK)” in SQL. How can we write the same using LINQ?

SqlException timeout expired without being reached

From time to time our server throw this well-known exception: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. This happens under pressure when the server is working on big requests. I did some research and found out that I could change connection string connection timeout […]

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