ado.net

DataReader hangs while mapping a record to an object

点点圈 提交于 2020-02-07 02:57:22
问题 I'm in the middle of a project where we are querying a database with more than 20 million records, applying several set of filters our query returns about 200 records (after waiting for about 1.30 minutes). After querying the database I try to create objects from this particular datareader but once every 15 or 16 records the asp.net process hangs (it hangs in the debugger) so I think it is a DataReader issue. This is driving me crazy. Here's the code I'm using using (IDataReader reader = cmd

difference between keeping database in app_data and connecting to an external database

放肆的年华 提交于 2020-02-04 18:45:32
问题 I want to know what is the difference between creating a database in app_data and connecting to a external database. i went through this question.but i am not clear idea. What's the difference between the database inside App_Data folder vs connecting to SQL Server? what is the advantages/disadvantage of using each type. 回答1: while developing, you will not see a big difference between both of them, but as many know, SQL server express has some limitations ( like supporting only 1 CPU) and this

What is the most annoying feature (or lack of feature) you have found in the Entity Framework?

旧城冷巷雨未停 提交于 2020-02-03 05:34:10
问题 I am starting with the Entity Framework. It sounds great. But I am wondering if I should watch out for some weakness somewhere. Any experience there? 回答1: You probably need to start prefixing these questions with the version you are talking about. A good amount of the annoyances have been fixed in the upcoming version in .NET 4.0. Here is what I would say after working with the first version for about 6 months using a decent size DB in sql 2k8(40+ tables, several tables with close to 1M rows,

How to manage parsing an null object for DateTime to be used with ADO.NET as DBNULL

不羁岁月 提交于 2020-02-01 16:40:46
问题 I have two DateTime objects, BirthDate and HireDate. They are correctly formatted as a string and when I pass them through to my data access layer, they need to be parsed into a DateTime object. DateTime hD = DateTime.Parse(hire); DateTime bD = DateTime.Parse(birth); //incase of a datestring being passed through dateStringPassed = "7/2/1969"; But sometimes, the strings hire and birth are null or empty "" , if the code is run like this, I get a FormatException error from Parsing a empty string

Why is TransactionScope using a distributed transaction when I am only using LinqToSql and Ado.Net

廉价感情. 提交于 2020-01-30 06:02:08
问题 We are having problems on one machine, with the error message: "MSDTC on server XXX is unavailable." The code is using a TransactionScope to wrap some LingToSql database code; there is also some raw Ado.net inside of the transaction. As only a single sql database (2005) is being accessed, why is a distributed transaction being used at all? (I don’t wish to know how to enable MSDTC, as the code needs to work on the server with their current setup) 回答1: This almost always happens when your

Why is TransactionScope using a distributed transaction when I am only using LinqToSql and Ado.Net

限于喜欢 提交于 2020-01-30 06:01:39
问题 We are having problems on one machine, with the error message: "MSDTC on server XXX is unavailable." The code is using a TransactionScope to wrap some LingToSql database code; there is also some raw Ado.net inside of the transaction. As only a single sql database (2005) is being accessed, why is a distributed transaction being used at all? (I don’t wish to know how to enable MSDTC, as the code needs to work on the server with their current setup) 回答1: This almost always happens when your

How do I include an apostrophe in the string passed to DataTable Select()?

会有一股神秘感。 提交于 2020-01-30 04:46:29
问题 The dt.Select(string) gives error missing operand when apostrophe symbol is in the string. what is the way to solve this error? or How to handle this error? 回答1: String value = "Rubens' Home"; // value you want to sanitize and search dt.Select(String.Format( "Location = '{0}'", value.Replace("'", "''"))); 来源: https://stackoverflow.com/questions/4906384/how-do-i-include-an-apostrophe-in-the-string-passed-to-datatable-select

Should I use ExecuteNonQuery for this db backup command

六眼飞鱼酱① 提交于 2020-01-30 03:28:32
问题 I have a method that allows me to kick off a back up of a data base. What I am wondering is if I should be using ExecuteNonQuery() in this context or if there is something better to use. Here is my code currently: public static void RunBackup(string dbName, string filePath, string backupName, string connString) { using(SqlConnection objConnection = new SqlConnection(connString)) { string commmandText = "BACKUP DATABASE @DBName TO DISK = @FilePath WITH NOFORMAT, NOINIT, NAME = @BackUpName,

Should I use ExecuteNonQuery for this db backup command

白昼怎懂夜的黑 提交于 2020-01-30 03:27:06
问题 I have a method that allows me to kick off a back up of a data base. What I am wondering is if I should be using ExecuteNonQuery() in this context or if there is something better to use. Here is my code currently: public static void RunBackup(string dbName, string filePath, string backupName, string connString) { using(SqlConnection objConnection = new SqlConnection(connString)) { string commmandText = "BACKUP DATABASE @DBName TO DISK = @FilePath WITH NOFORMAT, NOINIT, NAME = @BackUpName,

how do I mock sqlconnection or should I refactor the code?

痞子三分冷 提交于 2020-01-30 02:39:14
问题 I have the code below, I have read Moq and SqlConnection? and How can I stub IDBconnection, but I still have no idea how to mock the following sqlconnection. public class SqlBulkWriter : ISqlBulkWriter { private readonly string _dbConnectionString;; public SqlBulkWriter(string dbConnectionString) { this._dbConnectionString = dbConnectionString; } public void EmptyTable(string schema, string tableName) { using (var connection = new SqlConnection(this._dbConnectionString)) { try { connection