What size do you use for varchar(MAX) in your parameter declaration?
In this case you use -1.
In this case you use -1.
For logging purposes, I’m afraid there’s no nicer way of doing this but to construct the string yourself: string query = cmd.CommandText; foreach (SqlParameter p in cmd.Parameters) { query = query.Replace(p.ParameterName, p.Value.ToString()); }
Here’s the code: DataTable dt = new DataTable(); dt.Clear(); dt.Columns.Add(“Name”); dt.Columns.Add(“Marks”); DataRow _ravi = dt.NewRow(); _ravi[“Name”] = “ravi”; _ravi[“Marks”] = “500”; dt.Rows.Add(_ravi); To see the structure, or rather I’d rephrase it as schema, you can export it to an XML file by doing the following. To export only the schema/structure, do: dt.WriteXMLSchema(“dtSchemaOrStructure.xml”); Additionally, you can … Read more
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
You should supply the SqlParameter instances in the following way: context.Database.SqlQuery<myEntityType>( “mySpName @param1, @param2, @param3”, new SqlParameter(“param1”, param1), new SqlParameter(“param2”, param2), new SqlParameter(“param3”, param3) );
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
var reader = cmd.ExecuteReader(); var columns = new List<string>(); for(int i=0;i<reader.FieldCount;i++) { columns.Add(reader.GetName(i)); } or var columns = Enumerable.Range(0, reader.FieldCount).Select(reader.GetName).ToList();
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
You can just do the following: var connection = System.Configuration.ConfigurationManager. ConnectionStrings[“Test”].ConnectionString; Your assembly also needs a reference to System.Configuration.dll
First off, if you’re starting a new project, go with Entity Framework (“EF”) – it now generates much better SQL (more like Linq to SQL does) and is easier to maintain and more powerful than Linq to SQL (“L2S”). As of the release of .NET 4.0, I consider Linq to SQL to be an obsolete … Read more