ado.net

From .net how to I send many “batches” of SQL to Sql-Server without lots of round trips?

此生再无相见时 提交于 2019-12-21 16:32:51
问题 We have code that reads in a set of SQL script file, and after doing some processing on them splits them into batches by finding the “GO” keyword and then sends each batch to Sql Server using a separate SqlCommon. Is there a better way of doing this so we: Don’t have as many round trips Never have SQL Server waiting for the next batch Run faster. (The batches are mostly creating tables, index, views and stored procs. Speed is an issue as our integration tests calls the code often. The sql

Using IsolationLevel.Snapshot but DB is still locking

流过昼夜 提交于 2019-12-21 11:03:12
问题 I'm part of a team building an ADO.NET based web-site. We sometimes have several developers and an automated testing tool working simultaneously a development copy of the database. We use snapshot isolation level, which, to the best of my knowledge, uses optimistic concurrency: rather than locking, it hopes for the best and throws an exception if you try to commit a transaction if the affected rows have been altered by another party during the transaction. To use snapshot isolation level we

Is there a way to connect to a MySQL database without ssl?

空扰寡人 提交于 2019-12-21 10:47:09
问题 I'm trying to connect to a local MySQL DB. I have this connector: using(MySqlConnection conn = new MySqlConnection("Database=Studentenverwaltung;Port=3306;Data Source=127.0.0.1;User Id=root;Password=abc123")) { try { conn.Open(); Console.WriteLine("Opened!"); conn.Close(); } catch(Exception e) { Console.WriteLine("Cannot open Connection"); Console.WriteLine(e.ToString()); } } But I get this Exception: MySql.Data.MySqlClient.MySqlException (0x80004005): The host 127.0.0.1 does not support SSL

Why does Azure Database perform better with transactions

只愿长相守 提交于 2019-12-21 09:37:38
问题 We decided to use a micro-orm against an Azure Database. As our business only needs "inserts" and "selects", we decided to suppress all code-managed SqlTransaction (no concurrency issues on data). Then, we noticed that our instance of Azure Database responded very slowly. The " rpc completed " event occured in delays that are hundreds times the time needed to run a simple sql statement. Next, we benchmarked our code with EF6 and we saw that the server responded very quickly. As EF6 implements

Why does Azure Database perform better with transactions

谁说胖子不能爱 提交于 2019-12-21 09:36:04
问题 We decided to use a micro-orm against an Azure Database. As our business only needs "inserts" and "selects", we decided to suppress all code-managed SqlTransaction (no concurrency issues on data). Then, we noticed that our instance of Azure Database responded very slowly. The " rpc completed " event occured in delays that are hundreds times the time needed to run a simple sql statement. Next, we benchmarked our code with EF6 and we saw that the server responded very quickly. As EF6 implements

How to get identities of inserted data records using SQL bulk copy

孤人 提交于 2019-12-21 09:07:17
问题 I have an ADO.NET DataTable with about 100,000 records. In this table there is a column xyID which has no values in it, because the column is an auto-generated IDENTITY in my SQL Server database. I need to retrieve the generated IDs for other processes. I am looking for a way to bulk copy this DataTable into the SQL Server database, and within the same "step" to "fill" my DataTable with the generated IDs. How can I retrieve the identity values of records inserted into a table using the

Changing the Name of the Connection String that Entity Framework Uses

拟墨画扇 提交于 2019-12-21 08:00:48
问题 How do you change the name of the connection string that Entity Framework models are bound to by default? Let's say I create an Entity Framework data model named "Model1.edmx" by pointing it to a databased named "MyDb" and picking some objects to map using the Visual Studio add new item wizard. The EF model is in a class library project, so when the wizard completed, it automatically added a connection string named "MyDbEntities" to the App.Config file for the project. My model references

How to tell if a SqlConnection has an attached SqlDataReader?

不想你离开。 提交于 2019-12-21 07:56:12
问题 This is something now more of curiosity than actual purpose. If you have a SqlConnection opened and attach a SqlDataReader to it, and then try to run another query using the same SqlConnection then it will throw an error. My question is how does the SqlConnection know that a reader is attached to it. There is not a public property or anything for HasDataReader , so how does the SqlConnection class know? Original Question: (which is no longer relevant) Hi, I'm setting up a little thing for

yield return vs. return IEnumerable<T>

只谈情不闲聊 提交于 2019-12-21 07:15:32
问题 I've noticed something curious about reading from an IDataReader within a using statement that I can't comprehend. Though I'm sure the answer is simple. Why is it that whilst inside the using (SqlDataReader rd) { ... } if I directly perform a yield return the reader stays open for the duration of the read. But if I perform a direct return calling a SqlDataReader extension method (outlined below) that the reader closes before the enumerable can be actualized? public static IEnumerable<T>

Fastest way to retrieve data from a database in .NET?

心已入冬 提交于 2019-12-21 06:16:28
问题 Using ADO.NET, what is the fastest way to retrieve data from the database and populate the data into my business objects? Which one should I use? DBDataReader , DBDataAdapter , or any other classes? Is there a way to make this process automated? Let's say based on property names and matching them with database field names? 回答1: That sounds exactly like what an ORM or micro-ORM does. Here's the output of dapper-dot-net's performance tests (run about 1 minute ago, on a PC that is also busy