sqldatareader

SqlDataReader and concurrency/deallocation issues

泄露秘密 提交于 2019-12-11 18:49:27
问题 Running the below code is giving me an error: .NET Framework execution was aborted by escalation policy because of out of memory. System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first. I have the following code all over the place to run my sql: sql.Append(string.Format("SELECT TableId FROM ps_SavedTables WHERE guid = '{0}'", guid)); using (IDataReader reader = SqlHelper.GetDataReader(sql.ToString())) { if (reader.Read())

vb.net Filling Textbox On combobox Selected Index Changed with sql database

不羁岁月 提交于 2019-12-11 17:39:25
问题 after i programming this code for fill text-box when combo-box selected Index changed i got this error 'Object reference not set to an instance of an object.', whats can i do ?? Private Sub participant1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles participant1.SelectedIndexChanged Try Dim cmd As SqlCommand = New SqlCommand() Dim datareader As SqlDataReader = Nothing If Class1.sqlcon.State = ConnectionState.Open Then Class1.sqlcon.Close() End If Class1

How to differentiate duplicate column names from different source tables/subqueries by alias in an SQL select statement when using SqlDataReader?

核能气质少年 提交于 2019-12-11 14:01:56
问题 Suppose I have POCO entities being read from a database and they each have "ID" as their primary key column name. If selecting from more than one table or subquery with aliases a and b like select a.*, b.* from a, b , then the selected columns will include two ID columns (a.ID and b.ID), but the source table/subquery aliases are lost. I want to know if there's a way to preserve or dynamically obtain such a top-level alias for the source of the output columns of an arbitrary select query. I

DataReader associated with this Command which must be closed first

三世轮回 提交于 2019-12-11 05:35:57
问题 I am getting the following error; "There is already an open DataReader associated with this Command which must be closed first." is it because I have used the reader in foreach loop ? or what the problem might be ? Regards BK foreach( Apple a in listApple ) { .... using (SmartSqlReader reader = Db.CurrentDb.ExecuteReader(sp)) { while (reader.Read()) { a.blablabla += reader.GetInt32("BLA_BLA_BLA"); } } ..... } 回答1: Try the following: using (SmartSqlReader reader = Db.CurrentDb.ExecuteReader(sp

.SqlDataReader.ReadColumnHeader NullReferenceException

末鹿安然 提交于 2019-12-11 05:27:48
问题 This question is somewhat related to my previous one answer to which helped me to find the reason why this simple iteration thru SqlDataReader: m_aFullIDList = New Generic.List(Of Integer) While i_oDataReader.Read m_aFullIDList.Add(i_oDataReader.GetInt32(0)) End While m_iTotalNumberOfRecords = m_aFullIDList.Count does not return all the records. Turned out when Generic.List changes its Capacity to accommodate more elements (e.g from 2^19 to next one 2^20) at this point SqlDataReader simple

SqlDataAdapter.Fill() - Conversion overflow

自作多情 提交于 2019-12-11 05:25:54
问题 All, I am encountering "Conversion overflow" exceptions on one of the SqlDataAdapter.Fill() usages for a decimal field. The error occurs for value beginning 10 billion, but not till 1 billion. Here is the code: DataSet ds = new DataSet(); SqlDataAdapter sd = new SqlDataAdapter(); adapter.SelectCommand = <my SQL Command instance> adapter.Fill(ds); I have read using SqlDataReader as an alternate but we need to set the datatype and precision explicitly. There are at least 70 columns that I am

All code after SqlDataReader.ExecuteReader skipped

时光怂恿深爱的人放手 提交于 2019-12-11 05:15:43
问题 I have the following function: private void populate() { String connectionString = Properties.Settings.Default.Database; String selectString = "select artikelnummer, omschrijving from Artikels"; SqlDataReader reader = null; SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(selectString); reader = command.ExecuteReader(); connection.Open(); int x = 0; while (reader.Read()) { String item = String.Empty; item = Convert.ToString(reader[

Out Of Memory Exception - Using SqlDataReader and OpenXML

[亡魂溺海] 提交于 2019-12-11 03:48:02
问题 Edit: Due to memory issues, I am attempting to now use: http://blogs.msdn.com/b/brian_jones/archive/2010/06/22/writing-large-excel-files-with-the-open-xml-sdk.aspx But still running into some problems. String strWham = strExtract + strExtract2012; System.Data.SqlClient.SqlCommand objCmd = new System.Data.SqlClient.SqlCommand(strWham, objConn); objCmd.CommandTimeout = 3000; System.Data.SqlClient.SqlDataReader objReader; objReader = objCmd.ExecuteReader(); string path = @"\\wsi\userdata

Checking SQL MAX() Function returning null

泄露秘密 提交于 2019-12-11 03:11:54
问题 My problem is if my table is empty or the column on which I am using max function does not have the value I have specified, then why is sqlDataReader.hasRows TRUE? It is giving a null record...how do I solve this problem?? Thanks in advance. 回答1: An aggregate function like MAX() will always return one row per group. In your case, your group is the whole table. Therefore you get a one row resultset with the MAX value. Since you don't have data in your table, the MAX value is undefined,

SqlDataReader hangs on Dispose()

橙三吉。 提交于 2019-12-10 15:18:05
问题 I use the following approach to execute queries over database and read data: using(SqlConnection connection = new SqlConnection("Connection string")) { connection.Open(); using(SqlCommand command = new SqlCommand("SELECT * FROM TableName", connection)) { using (SqlDataReader reader = command.ExecuteReader()) { // read and process data somehow (possible source of exceptions) } // <- reader hangs here if exception occurs } } While reading and processing data some exceptions can occur. The