Calling stored procedure with return value

You need to add return parameter to the command: using (SqlConnection conn = new SqlConnection(getConnectionString())) using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = parameterStatement.getQuery(); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue(“SeqName”, “SeqNameValue”); var returnParameter = cmd.Parameters.Add(“@ReturnVal”, SqlDbType.Int); returnParameter.Direction = ParameterDirection.ReturnValue; conn.Open(); cmd.ExecuteNonQuery(); var result = returnParameter.Value; }

ADO.NET |DataDirectory| where is this documented?

|DataDirectory| is a substitution string so you can configure the location of your database file separately. So instead of: SqlConnection c = new SqlConnection ( @”Data Source=.\SQLDB; AttachDbFilename=C:\MyDB\Database.mdf;Initial Catalog=Master”); you do the following: // Set |DataDirectory| value AppDomain.CurrentDomain.SetData(“DataDirectory”, “C:\myDB”); // SQL Connection String with |DataDirectory| substitution string SqlConnection c = new SqlConnection ( @”Data Source=.\SQLDB; … Read more

Using MySQL with Entity Framework [closed]

It’s been released – Get the MySQL connector for .Net v6.5 – this has support for [Entity Framework] I was waiting for this the whole time, although the support is basic, works for most basic scenarios of db interaction. It also has basic Visual Studio integration. UPDATE http://dev.mysql.com/downloads/connector/net/ Starting with version 6.7, Connector/Net will no … Read more

SET NOCOUNT ON usage

Ok now I’ve done my research, here is the deal: In TDS protocol, SET NOCOUNT ON only saves 9-bytes per query while the text “SET NOCOUNT ON” itself is a whopping 14 bytes. I used to think that 123 row(s) affected was returned from server in plain text in a separate network packet but that’s … Read more

ExecuteReader requires an open and available Connection. The connection’s current state is Connecting

Sorry for only commenting in the first place, but i’m posting almost every day a similar comment since many people think that it would be smart to encapsulate ADO.NET functionality into a DB-Class(me too 10 years ago). Mostly they decide to use static/shared objects since it seems to be faster than to create a new … Read more

Entity Framework and Connection Pooling

Connection pooling is handled as in any other ADO.NET application. Entity connection still uses traditional database connection with traditional connection string. I believe you can turn off connnection pooling in connection string if you don’t want to use it. (read more about SQL Server Connection Pooling (ADO.NET)) Never ever use global context. ObjectContext internally implements … Read more