Questions tagged [dbdatareader]

32 questions
7
votes
1 answer

Is it ok to dipose a DbCommand before iterating the DbDataReader

I have a simple application that needs to execute certain queries to get the database schema information. I have written a simple method that executes a query and returns a reader, something like this - public static DbDataReader…
alwayslearning
  • 4,493
  • 6
  • 35
  • 47
5
votes
1 answer

Generic DbDataReader to List mapping

I am having a slight issue (more like an annoyance) with my property binding data access classes. The problem is that the mapping fails when there exists no column in the reader for corresponding property in class. Code Here is the mapper class: //…
Kevin
  • 2,684
  • 6
  • 35
  • 64
4
votes
1 answer

How to populate a table valued parameter using a custom DbDataReader?

According to MSDN, System.Data.SqlClient supports populating table-valued parameters from DataTable, DbDataReader or IEnumerable objects. I wrote the following code which populate a table valued paremeter using…
tigrou
  • 4,236
  • 5
  • 33
  • 59
3
votes
1 answer

DbDataReader error: Invalid attempt to call Read when reader is closed

Hi I am trying to get return the DataReader from a method but it returns a closed DbDataReader object there. Any Idea to sort out this issue. I am open to any suggestions to make the code better. Thanks UPDATE I don't want to leave the Database…
Scorpion
  • 4,495
  • 7
  • 39
  • 60
3
votes
2 answers

SqlDataReader / DbDataReader implementation question

Does anyone know how DbDataReaders actually work. We can use SqlDataReader as an example. When you do the following cmd.CommandText = "SELECT * FROM Customers"; var rdr = cmd.ExecuteReader(); while(rdr.Read()) { //Do something } Does the data…
Jose
  • 10,891
  • 19
  • 67
  • 89
2
votes
5 answers

Getting a constraints exception when loading a DataReader in a DataTable

I run a Merge query against a SQL2008 db that returns the output from the merge using the following c# code: cmd.CommandText = query; if (conn.DBConn.State == ConnectionState.Closed) conn.DBConn.Open(); DbDataReader dbReader =…
callisto
  • 4,921
  • 11
  • 51
  • 92
2
votes
3 answers

Convert List to DBDataReader

How can I Convert a List personList to DBDataReader ? In the code that I have given below, I am trying to bulk insert personList. I have around 500k records, and the method WriteToServer expects a DBDataReader and I have a List. How…
Illep
  • 16,375
  • 46
  • 171
  • 302
2
votes
1 answer

How to check in Access VBA whether ODBC SQL Server table has write access?

I have a ODBC Linked table in Microsoft Access which is connected to sql server. For some users the login which connect access to SQL Server has access to only one database with db_datareader role so they cannot edit any data in the tables. For…
Omid Sadeghi
  • 675
  • 7
  • 16
2
votes
1 answer

Why does ExecuteReader() pad strings with traling spaces?

I have two queries: Q1: select name from presidents where country = 'USA' Q2: select 'Obama' as name from presidents where country = 'USA' When using System.Data.Odbc.OdbcCommandExecuteReader then the returned DbDataReader contains 'Obama' in case…
Patrick Fromberg
  • 1,313
  • 11
  • 37
2
votes
2 answers

Avoid code duplication when reading/serializing from DbDataReader?

Consider the FetchData method below. It is designed to avoid duplicating the database query code every time you want to fetch some data from the database. List myData = new List { …
l33t
  • 18,692
  • 16
  • 103
  • 180
2
votes
4 answers

Open DataReader issues while using Dapper.Net in high traffic scenario - now to resolve?

Here is an example of one of our data calls in our DAL using Dapper.Net: /// /// Handles db connectivity as Dapper assumes an existing connection for all functions /// Since the app uses three databases, pass in the connection…
ElHaix
  • 12,846
  • 27
  • 115
  • 203
1
vote
2 answers

Get number of current connections to a specific database using an SQL Server account with db_datareader database role

I have an account with db_datareader database role set on my database test_db. Using SSMS I log in using this account (with SQL Server Authentication) and I open a new query window in order to get the number of current connections to test_db…
Willy
  • 9,848
  • 22
  • 141
  • 284
1
vote
1 answer

DbDataReader causing OutOfMemoryException

I'm reading data from an Oracle database using the DbDataReader (OracleDataReader) class. I'm running the program in Visual Studio 2010, with a 64-bit Windows 10 Enterprise laptop with 32GB RAM (20GB free), using .NET 3.5 (upgrading to a newer .NET…
1
vote
0 answers

SSMS Expanding Tables Lock Timeout for DB_READER

I have a very odd issue. If a user with public and db_datareader access attempts to expand the tables in SSMS 17.2 they receive a Lock request time out period exceeded. (Microsoft SQL Server, Error: 1222) error. If a user with sysadmin does the…
Peter Godwin
  • 77
  • 11
1
vote
1 answer

What is async in System.Data.Common.DbDataReader.ReadAsync?

I am looking at the code for DbDataReader (also DbCommand) at MS reference and can't figure out what is async in ReadAsync() method. virtual public Task ReadAsync(CancellationToken cancellationToken) { if…
gajo357
  • 958
  • 12
  • 22
1
2 3