sqldatareader

Convert C# 2.0 System.Data.SqlTypes.SqlXml object into a System.Xml.XmlNode

懵懂的女人 提交于 2019-12-06 05:05:23
I seem to always have problems with converting data to and from XML in C#. It always wants you to create a full XMLDocument object even when you think you shouldn't have to. In this case I have a SQLXML column in a MS SQL 2005 server that I am trying to pull out and push into a function that requires an XMLNode as a parameter. You would think this would be easy, but outside of converting it to a string and creating a new XMLNode object I cannot figure out the right way to do it. I can use an SqlDataReader, the sqlComm.ExecuteReader() to load the reader, and sqlReader.GetSqlXml(0) to get the

closing SQLDataReaders - how to tell if they are closed?

怎甘沉沦 提交于 2019-12-05 23:40:57
I'm finding that I'm having some website connection pool issues and I'm in the process of tracking them down. I know one thing to look for is to make sure that any SQLDataReaders get closed and I've gone though and made sure they are. One question that popped up in my head was about methods that return SQLDataReaders and how they get closed (or not). So here's how I have things setup and some example methods: public static SqlDataReader ExecuteReader(SqlCommand cmd) { SqlConnection c = new SqlConnection(Properties.Settings.Default.DatabaseConn); cmd.Connection = c; c.Open(); return cmd

SqlDataReader Performance List<string[]> or List<object[]>

旧城冷巷雨未停 提交于 2019-12-05 23:18:01
问题 I have been experimenting with ways to read data from a SQL server as quickly as possible and I came across an interesting discovery. If I read the data into a List<object[]> instead of a List<string[]> , performance increases by more than double. I suspect this is due to not having to call the ToString() method on the fields, but I always thought that using objects had a negative impact on performance. Is there any reason to not use a list of object arrays instead of string arrays? EDIT: One

The data types text and varchar are incompatible in the equal to operator

a 夏天 提交于 2019-12-05 18:09:59
I am trying to access all the records from database on a data grid view depending upon the type of user logging in through a form having 2 text-boxes for user_name and password respectively and on submit button records are displayed. But the code I have written is giving me the following error: The data types text and varchar are incompatible in the equal to operator. Please suggest changes. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System

Task when all, connection is closing

淺唱寂寞╮ 提交于 2019-12-05 09:10:48
I'm trying to execute multiple SqlDataReaders using Task.WhenAll. But when the tasks are awaited I get "System.InvalidOperationException: Invalid operation. The connection is closed". Creation of tasks: List<Task<SqlDataReader>> _listTasksDataReader = new List<Task<SqlDataReader>>(); _listTasksDataReader.Add(GetSqlDataReader1(10)); _listTasksDataReader.Add(GetSqlDataReader2(10)); SqlDataReader[] _dataReaders = await Task.WhenAll(_listTasksDataReader); My "SqlDataReader" methods: public Task<SqlDataReader> GetSqlDataReader1(int recordCount) { using (var sqlCon = new SqlConnection

ADO.Net DataReader timeout issue

送分小仙女□ 提交于 2019-12-05 07:27:37
I am using ADO.Net + C# + VSTS 2008 + ADO.Net to connect to SQL Server 2008 Enterprise. I am using almost the same pattern/sample mentioned here -- using ADO.Net DataReader to retrieve data one entry (row) by one entry (row). http://msdn.microsoft.com/en-us/library/haa3afyz.aspx My question is, if I set the SqlCommand timeout in this sample, 1. I think the timeout applies to how much time we could use as maximum value to retrieve one specifc row, not the total timeout for the whole data entry-by-entry loop? BTW: loop I mean, while (reader.Read()) { Console.WriteLine("{0}\t{1}", reader.GetInt32

Generic method to read data from DataReader

☆樱花仙子☆ 提交于 2019-12-05 04:33:26
I am currently using this method to read data from DataReader - private T GetValue<T>(object obj) { if (typeof(DBNull) != obj.GetType()) { return (T)obj; } return default(T); } calling above method as - GetValue<int>(dataReader["columnName1"]) GetValue<string>(dataReader["columnName2"]) GetValue<float>(dataReader["columnName3"]) However this fails when columnName3 is having values as 7200000 with error Invalid Cast Exception. I am thinking to modify my method to replace - return (T)obj; with return (T)Convert.ChangeType(obj, typeof(T)); But looking forward for a better way as this change will

ADO.NET Question: When to use DataReader, DataAdapter

一个人想着一个人 提交于 2019-12-04 20:22:10
问题 i just wondering, what things i have to consider when using DataReader and DataAdapter in fetching data from the database and whats the difference between this two other the datareader needs open connection and the datadapter does not... In our projects, were using DataReader in ALL our DAL, we never use dataadapter. So I wondering what scenario would it been better to use DataAdapter + Datatable combo than using DataReader. Thanks in advance. 回答1: DataReader : This is best used when you just

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

谁都会走 提交于 2019-12-04 05:24:01
A fairly large web application written in C# keeps throwing up 2 errors: 'ExecuteReader requires an open and available Connection. The connection's current state is open.' and 'Invalid attempt to call Read when reader is closed.' These errors were sporadic -- the pages used to load fine about 95% of the time, but recently they've become endemic, they're occurring all the time and basically crippling the application's functionality. The web app is highly reliant on an MS SQL database, and the errors appear to not be confined to just one page, but nearly all the pages that connect to the

SqlDataReader Performance List<string[]> or List<object[]>

余生长醉 提交于 2019-12-04 05:12:24
I have been experimenting with ways to read data from a SQL server as quickly as possible and I came across an interesting discovery. If I read the data into a List<object[]> instead of a List<string[]> , performance increases by more than double. I suspect this is due to not having to call the ToString() method on the fields, but I always thought that using objects had a negative impact on performance. Is there any reason to not use a list of object arrays instead of string arrays? EDIT: One thought I just had was the storage size of this data. Will storing the data in object arrays take more