sqldatareader

SqlDataReader.GetValue Hangs

耗尽温柔 提交于 2019-12-08 05:11:24
问题 I run a process built in C# .Net 4.6.1 that accesses a SQL Server database. The process runs on Windows Server 2012 R2 Standard. The SQL Server database is on another server with SQL Server version 11.0.6567.0 The process executes the following code: 01 var readStatement = “select * from TableA order by ColumnX,ColumnY, ColumnZ offset 0 rows”; // TableA has 13 million rows 02 var readCommand = new SqlCommand(readStatement, myConnection) { CommandTimeout = 72000 }; 03 var reader = readCommand

SQL Data Reader: Invalid attempt to read when no data is present

不羁岁月 提交于 2019-12-08 02:57:27
I am trying to use a SqlDataReader to run a query and then display the results in a messagebox, but I keep getting the error Invalid attempt to read when no data is present. Here is my code. public void button1_Click(object sender, EventArgs e) { string results = ""; using (SqlConnection cs = new SqlConnection(@"Server=100-nurex-x-001.acds.net;Database=Report;User Id=reports;Password=mypassword")) { cs.Open(); string query = "select stationipaddress from station where stationname = @name"; using (SqlCommand cmd = new SqlCommand(query, cs)) { // Add the parameter and set its value -- cmd

Execute stored procedure in Entity Framework, return List<DataTable> or DataSet

大憨熊 提交于 2019-12-08 02:23:54
问题 How do I modify the below method to return a List< DataTable> or a DataSet? I want to make it generic so it can return multiple resultsets from the database. public static DataTable ExecuteStoredProcedure(ObjectContext db, string storedProcedureName, IEnumerable<SqlParameter> parameters) { var entityConnection = (EntityConnection) db.Connection; var conn = entityConnection.StoreConnection; var initialState = conn.State; var dt = new DataTable(); try { if (initialState != ConnectionState.Open)

closing SQLDataReaders - how to tell if they are closed?

二次信任 提交于 2019-12-07 16:33:18
问题 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

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

时间秒杀一切 提交于 2019-12-07 12:01:16
问题 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

SqlDataReader.GetValue Hangs

拟墨画扇 提交于 2019-12-07 05:06:25
I run a process built in C# .Net 4.6.1 that accesses a SQL Server database. The process runs on Windows Server 2012 R2 Standard. The SQL Server database is on another server with SQL Server version 11.0.6567.0 The process executes the following code: 01 var readStatement = “select * from TableA order by ColumnX,ColumnY, ColumnZ offset 0 rows”; // TableA has 13 million rows 02 var readCommand = new SqlCommand(readStatement, myConnection) { CommandTimeout = 72000 }; 03 var reader = readCommand.ExecuteReader(); 04 while (reader.Read()) 05 { 06 foreach (var columnName in columnNames) 07 { 08

ADO.Net DataReader timeout issue

我是研究僧i 提交于 2019-12-07 02:50:53
问题 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

Generic method to read data from DataReader

帅比萌擦擦* 提交于 2019-12-07 00:35:51
问题 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

Can I reset and loop again through MySqlDataReader?

喜你入骨 提交于 2019-12-06 16:50:06
I have a MySqlDataReader object, with the result of this query : SELECT warehouse, leasing, transportation, maintenance, manpower FROM retail WHERE zone = 'Central' GROUP BY warehouse And then I loop through the DataReader once, while (r2.Read()) { strXml.AppendFormat("<set label = '{0}'></set>",r2["warehouse"].ToString()); } And now I want to loop through it again...!! I know that DataReader is only a 'forward-only' object.. But is there any other solution for me here ? I'm asking, is there any any efficient way to hold data other than MySqlDataReader ? You can use below : using

Execute stored procedure in Entity Framework, return List<DataTable> or DataSet

北城余情 提交于 2019-12-06 10:26:34
How do I modify the below method to return a List< DataTable> or a DataSet? I want to make it generic so it can return multiple resultsets from the database. public static DataTable ExecuteStoredProcedure(ObjectContext db, string storedProcedureName, IEnumerable<SqlParameter> parameters) { var entityConnection = (EntityConnection) db.Connection; var conn = entityConnection.StoreConnection; var initialState = conn.State; var dt = new DataTable(); try { if (initialState != ConnectionState.Open) conn.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = storedProcedureName; cmd