sqldatareader

Timeout exception causes SqlDataReader to close?

I'm trying to pull some binary data from a database and write them to pdf files. For the most part, this is going along swimmingly, but the occasional row of data seems to throw a particular error - Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Keep in mind, this onl...

c#/sql-server, trying to get data to two ddl's from two tables...in one sqlDataReder

Hi all, Well, i am tring to do something nice (nice for me, simple for you guys), i was told i can do it, but i have no idea where to start. I have two DDL's in a page, i need on page_load to popolate both, each one gets data from deferent table with no relaition between them (suppliers/catagories). i know how to do it with two DB conne...

SQL Data Reader - handling Null column values

I'm using a SQLdatareader to build POCOs from a database. The code works except when it encounters a null value in the database. For example, if the FirstName column in the database contains a null value, an exception is thrown. employee.FirstName = sqlreader.GetString(indexFirstName); What is the best way to handle null values in th...

why I can't use two datareader in one procedure?

Hi everyone, can you explain me why I can't use two datareader in on procedure? Here is the sample code: Private Sub Do_Execute() Dim conx as SqlConnection Dim cmd1 as SqlCommand Dim cmd2 as SqlCommand Dim drd1 as SqlDataReader Dim drd2 as SqlDataReader conx = new SqlConnection("connection string") conx.Open() c...

Lightweight readonly alternative to DataTable for storing data from SqlDataReader?

I am suing SqlDataReader to read data from SQL Server. However sometimes I want to cache my data in memory as read only lightweight connection free object. I couldn't find any options for me in the BCL. Do I need to write my own implementation of such container, or are any available? What alternatives do I have for storing data from dat...

How Can I check whether DataReader has Data or not?

Hi All, Again I have problem with checking whether DataReader object has data or not? Dim cmd as SqlCommand Dim drd as SqlDataReader cmd = New SqlCommand ("SELECT * FROM Stock", conx) drd = cmd.ExecuteReader() ''HERE I WOULD LIKE TO CHECK WHETHER drd has Data or not While (drd.Read()) { txtName....

SQL Server and SqlDataReader - Trillion Records - Memory

I've never tried this - so I don't know if I'd run into memory issues. But can a SqlDataReader read a trillion records? It's all streamed correct? I'm a little green to what the SQL/TDS protocol is doing under the covers. UPDATE Translate Trillion to mean very large number. I probably should have said something like 1 billion or 100 mi...

SQLiteDataReader and OdbcTransaction : how to limit Insert phrases ?

Hello, I'm looking for a workaround, my destination server (Rainingdata D3) is returning an error when my reader is returning to much lines. explications: 1 datareader reads from my sqlite database, 2 via a while reader-loop i'm inserting in the destination database (ODBC- D3 database) i don't have a other solution oder other dataprov...

XLinq vs. SqlDataReader performance

As a part of trying to repair stuff in a fairly messed up legacy system I have a method making a call to a stored procedure in our SQLServer database. Nothing in this set up is ideal, but it is what I have got to work with. The two options I have is to use a SqlDataReader to read the stream as rows from the database, or to be handed the ...

Select Column values from SqlDataReader command

I have a table containing two columns in SQL that I want to extract values from. The problem though is I do not know how to retrieve column 2's values in C# code. I am using SQL Server 2008 and VS. Do I have to use an OUTPUT parameter in the SP? If so, how would I specify this SP? I have experimented with OUTPUT parameters, but I am...

Get table name from ADO.NET Field?

If i do a select on user.name, user.post, t.name with t being tag_name AS t is there a way to resolve the full name using ADO.NET? I found SqlDataReader.GetName but that is getting me only name as the first result. I would like to know if it belongs to user or tag_name. Is there a way to have it tell me? ...

How can I "detach" a SqlDataReader from its SqlConnection object?

I have a method ("GetDataReader," let's call it) that returns a SqlDataReader. It's inside a Singleton DataFactory class that maintains a persistent connection to the database. The problem with this is that after being returned, the DataReader is still "connected" to the Connection object in my DataFactory. So, I have to make sure the...

Using SqlDataReader to fill an ArrayList?

I'm trying to implement a method which will take a given connection string and return an ArrayList containing the contents of a SQL view. I've verified the validity of the connection string and the view itself. However I don't see what the problem is in the code below. In debug, when it runs the ExecuteReader method and then try to ente...

C# SqlDataReader Execution Statistics and Information

Hi, I am creating an automated DB Query Execution Queue, which essentially means I am creating a Queue of SQL Queries, that are executed one by one. Queries are executed using code similar to the following: using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString)...

How to (efficiently) convert (cast?) a SqlDataReader field to its corresponding c# type?

First, let me explain the current situation: I'm reading records from a database and putting them in an object for later use; today a question about the database type to C# type conversion (casting?) arose. Let's see an example: namespace Test { using System; using System.Data; using System.Data.SqlClient; public enum ...

using sqldatareader instead of recordset vb.net

I am new to this and had this question. Can i use SQLDataReader instead of a Recordset. I want to achieve the following result in an SQLDataReader. Dim dbConn As New ADODB.Connection Dim rs As New ADODB.Recordset Dim sqlstr As String = "SELECT Name,Status FROM table1 WHERE id=" + item_id.Value.ToString rs.Open(SQL, dbConn) While Not rs....

When DataReader become empty?

I have the below code : if (reader.HasRows) { while (reader.Read()) { DataRow searchedDR = ds.Tables[dr["name"].ToString()].Rows.Find(reader["ID"].ToString()); if (searchedDR != null) ds.Tables[dr["name"].ToString()].Rows.Remove(searchedDR); } } When this block of code done successfully the data...

add column while copying data in sql

I'm using SqlBulkCopy to bulk insert some records from one table into another table. The query is using a SqlDataReader to get the data. The one difference that matters (besides column order which is handled in the mappings) between the tables is that the destination table has a date column into which the current date needs to be added...

SQLDataReader: Dealing with null values

Some tables I am dealing with have null values and are throwing errors. So far ive tried a few solutions to deal with the nulls with no success. Here are the code samples from my efforts so far; If (r("datemodified").Equals(DBNull.Value)) Then datemodified = String.Empty Else datemodified = (...

(string)reader[0] vs Convert.ToString(reader[0])

what's better var s = (string)reader[0] or var s = Convert.ToString(reader[0]) ? ...