sqlconnection

Connection leak (C#/ADO.NET) even though SqlConnection created with using

删除回忆录丶 提交于 2020-06-17 09:09:54
问题 I have a program that loads a large quantity of data (~800K-1M rows per iteration) in a Task running on the threadpool (see offending code sample below); no more than 4 tasks running concurrently. This is the only place in the program that a connection is made to this database. When running the program on my laptop (and other coworkers identical laptops), the program functions perfectly. However, we have access to another workstation via remote desktop that is substantially more powerful than

Getting data from a database and returning it in XML

萝らか妹 提交于 2020-02-25 10:07:09
问题 I'm currently using a store procedure with a variable to get data from a database but I was the return the result in XML. I can get all data from a table using this store procedure and it returns in XML: public string GetAllPatients() { string conn = @"Data Source=SNICKERS\SQLEXPRESS;Initial Catalog=VerveDatabase;Integrated Security=True"; DataSet oDS = new DataSet(); SqlDataAdapter oCMD = new SqlDataAdapter("getAll", conn); oCMD.Fill(oDS, "AllPatients"); return oDS.GetXml(); } However when I

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

Why isn't SqlConnection disposed/closed?

核能气质少年 提交于 2020-01-24 05:14:34
问题 Given the method: internal static DataSet SelectDataSet(String commandText, DataBaseEnum dataBase) { var dataset = new DataSet(); SqlConnection sqlc = dataBase == DataBaseEnum.ZipCodeDb ? new SqlConnection(ConfigurationManager.AppSettings["ZipcodeDB"]) : new SqlConnection(ConfigurationManager.AppSettings["WeatherDB"]); SqlCommand sqlcmd = sqlc.CreateCommand(); sqlcmd.CommandText = commandText; var adapter = new SqlDataAdapter(sqlcmd.CommandText, sqlc); adapter.Fill(dataset); return dataset; }

SqlConnection error Named Pipes Provider

纵饮孤独 提交于 2020-01-14 05:18:07
问题 A little background: I have a Windows .NET application that is in use by approximately 40 field employees across North America. This program allows the users to enter data while in the field (away form internet access) and then synchronizes to our Sql Server 2005 database at night. A couple days ago, two of my users reported getting the following error when they performed an action that would attempt to connect to our server database (which uses .NET's SqlConnection class). System.Data