1,142 questions
0
votes
1
answer
89
views
there is already a datareader associated with this command which must be closed first
Hellow everyone, I hope someone can help me.
I have a vb.net console application that started giving me headaches just recently.
I have the next Code:
Imports System.Data.SqlClient
Dim SqlQuery = New ...
0
votes
1
answer
79
views
SQL Server XML column is string in .NET using SqlDataReader
Why if in SQL Server, I have a column defined as XML type, and in .NET with SqlDataReader/SqlDataAdapter I have a string?
See the example in the screenhsot, cast c1 in XML, but .NET gets a string.
I ...
0
votes
0
answers
69
views
Can I get the type (class) of a table using SQLite in C#?
I have multiple tables for separate classes and want to print their data using a single method.
My code so far.
In the while (reader.Read()) loop the program doesnt enter the if statements (reader....
0
votes
2
answers
469
views
DataAdapter .Fill is slow. How to make something similar with DataReader?
I have a utility class with SQLDataAdapter reading data. Problem is when I try to return data from a SP using DataAdapter.fill, it almost takes around 1min,16 seconds to do the Fill operation and ...
0
votes
0
answers
30
views
How to get IdentityUser name using SqlDataReader
I have this model:
public class Model
{
public IdentityUser UserId { get; set; }
public string data { get; set; }
public decimal data2 { get; set; }
public DateTime data3 { get; ...
0
votes
0
answers
60
views
Converting SqlDataReader to SequentialAccess to avoid out-of-memory errors?
I'm currently hitting out of memory errors with the code shown here, and I want to move my SqlDataReader to SequentialAccess to see if that helps.
I originally stumbled across this via the following ...
-2
votes
1
answer
110
views
Is there a way in C# to override the 8000 byte limit when using SQLDataReader.GetBytes? [closed]
I have a database that has file data stored in an image column. I need to be able to extract the data in this image column and create a document on disk.
I am using C# to run the queries, extract the ...
5
votes
2
answers
133
views
Does DataReader of ADO.NET Interact with the SQL Server For Every Row it fetches or Does it maintain a cache or buffer?
I've used datareader for reading data from SQL Server. Now let us say I've 20 rows in the table. So does my ADO.NET make 20 interactions with the SQL Server to fetch the data or does it bring all the ...
0
votes
1
answer
82
views
SqlDataReader inconsistent speed looping through rows
I have a .NET project in which I run two SQL queries that have more or less the same complexity i.e., same number of NULL checks and INNER joins.
The execution of the first SqlDataReader takes much ...
0
votes
1
answer
759
views
C# SqlDataReader.GetInt64 System.InvalidCastException: Specified cast is not valid
I know the usual answers for this and they don't seem to apply.
We have a process that goes through data from numerous vendors and gets it into one consistent stream. We added a vendor recently that ...
1
vote
0
answers
50
views
OutOfMemoryException on reading 180k records using ADO.NET sqldatareader
so I have the same problem as many others. I have read through articles and SO questions that are similar but never clearly understood how to resolve this problem.
I am using a SQLDataReader to run a ...
1
vote
3
answers
731
views
C# SqlDataReader Get Value By Column Name (Case Insensitive)
Using the methods of the SqlDataReader, I can get the value of a column by passing in its name.
while (dr.Read())
{
size = dr["size"].ToString();
name = dr["name"]....
1
vote
0
answers
90
views
Convert subsequent SQL to case insensitive in SQL Server
We are converting from ASE (Sybase) to SQL Server (yay!)
Unfortunately, we have a ton of SQL built into our C# code which assumes ASE's default case insensitivity.
We are using ADO for both.
Is there ...
0
votes
1
answer
610
views
How to use SqlDataReader in a loop?
I need to process the data from the list using SqlDataReader. To do this, I wrote a for loop in which the data for the query will be supplied and get into SqlDataReader. But after the first iteration, ...
-2
votes
2
answers
977
views
Reading all records from sqlite local file using c#
I am trying to read all the records from a local sqlite file. But for some reason, the code that I am using isn't reading all records. It is reading only the second row, that too only few columns, not ...
0
votes
0
answers
68
views
Can I read SQLite datatime field as raw string?
I have public SQLite database, a lot of computer can write data to that DB. Unfortunately, Datetime format in different computer is different.
Sqlite can store different Datatime format
Sqlite ...
0
votes
1
answer
97
views
SqlDataReader only reads partial data from JSON column
I have the following code but it only reads the last part of the JSON value:
public string GetUsersJson(long systemOrgId)
{
var query = @"DECLARE @OrgId bigint = @systemOrgId
SELECT e....
-1
votes
1
answer
706
views
Calling SQL Server stored procedure with result set and return value
Is there a way to get a dataset and a return value from a SQL Server stored procedure with just one execution of the stored procedure?
Is there a way to get both in just one call?
TIA
Marcos Galvani
...
0
votes
1
answer
80
views
Getting an error: Invalid attempt to call Read when reader is closed
I have 2 select statements in a stored procedure and getting result set in a data reader.
My objective is to merge the data from 2 selects into a single JSON string.
I am using nested do while and at ...
0
votes
0
answers
57
views
SqlCommand Time Out After Repeat (Simple) Queries in .NET / F#
I am running a relatively simple query using SqlConnection / SqlCommand / SqlDataReader.
The code looks like the below. I have this inside of a function where I pass in a date to call this function, ...
0
votes
0
answers
286
views
SQLDataReader returns null even when data exist
I'm suddenly experiencing issues with obtaining data from the MS SQL DB using the SQLDataReader. The problem is that it's only happening for one specific table and the exactly the same approach works ...
-1
votes
1
answer
123
views
Running DataReader from separate class file in webforms c#
I placed my DB reader in a separate class file because I didn't want to keep rewriting it but I keep getting the error:
Object reference not set to an instance of an object. db was null
This is my ...
1
vote
2
answers
1k
views
How to resolve this SqlDataReader "Possible null reference assignment" warning?
I just cannot figure out what is needed to resolve the warning about the possible null reference assignment in the following case:
item.UniqueId = Convert.IsDBNull(reader["UniqueID"]) ? ...
1
vote
1
answer
122
views
SQL Server and SqlDataReader
I am trying to create a login page together with a SQL Server database but when I am trying to use the SqlDataReader, I get an error
System.Data.SqlClient.SqlException: 'Incorrect syntax near ','
I'...
0
votes
0
answers
207
views
EF Core 6 sproc call requires sproc to include a select 0;
Summary:
.NET Core 6.0, Entity Framework Core 6.0.2.0
Calling a sproc via EF's command.ExecuteReader().
If I don't include a select 0; at the top of my sproc, no results are
returned.
My C# code:
...
1
vote
1
answer
739
views
Stored Procedure returns results in Sql correctly but not in C# using SqlDataReader
SQL Server table:
CREATE TABLE [dbo].[MessageSubscribers]
(
[SubscriberId] INT IDENTITY (1, 1) NOT NULL,
[SubscriberCode] NVARCHAR (MAX) NULL,
[SubscriberName] NVARCHAR(MAX) NOT ...
0
votes
2
answers
389
views
Why is ExecuteReader closing?
I am developing an app in WPF. I am trying to fetch email, extract data, save it in DB and work with it in DataGrid. To avoid saving duplicates, I have made a method for that. My problem is, that I ...
1
vote
1
answer
257
views
SqlDataReader.GetSchemaTable returns data type = int when all values are null
The following code snippet:
using (DataTable schemaTable = reader.GetSchemaTable())
{
for (int i = 0; i < reader.FieldCount; i++)
{
DataRow drow = schemaTable.Rows[i];
...
1
vote
0
answers
73
views
SQL Command executes, SQL Statement viewable in SQL Profiler returns rows, DataReader has no rows
I'm working on an application that uses C# to do a search like so:
using (SqlCommand cmd = new SqlCommand("[dbo].[usp_Search]", commercialConn))
...
1
vote
4
answers
1k
views
Reading SQL query result with multiple columns in C#
This code is partially working. It gives me the first and second columns in the first row. But the SQL query result has 3 rows, and I want to read them too.
How can I do that? Maybe my method is wrong ...
0
votes
1
answer
947
views
Reading a GUID string as a GUID from executing a SQL script throws an invalid cast exception
We are executing a SQL script and reading the results using a SQLDataReader. This line is throwing an InvalidCastException:
reader.GetGuid(1)
The object being returned is a GUID as a string ("...
2
votes
2
answers
293
views
SqlDataReader.GetValue(0) cannot get anything
I am writing some script to read the sql query result at Intouch environment, it's not exactly C# language but similar. I just want to get the "1" stored in my "SQLTest" variable (...
0
votes
1
answer
1k
views
Convert SqlDataReader to object for .NET Framework 4
I am working on a class Library with .NET Framework 4.0. I have managed to pull a row using ADO.NET, but I'm unable to read individual values. I want the end result in class object. I have tried ...
1
vote
1
answer
622
views
System.InvalidOperationException: 'Invalid attempt to call FieldCount when reader is closed.'
I have this class that tries to read from the sql reader
using Microsoft.Data.SqlClient;
using MinimalAPI.Models.ConnectUI;
namespace ConnectAPI.SQL.BAL
{
public class ...
1
vote
0
answers
653
views
SQL Data Reader (NpgsqlDataReader) skipping 1st line
So I have a pretty simple reader, which executes given query:
connection.Open();
using (var r = command.ExecuteReader())
{
while (r.Read())
...
3
votes
1
answer
3k
views
"An existing connection was forcibly closed by the remote host" in .NET 3.5
I'm writing a program for viewing, archiving and restoring SQL-Data.
The problem occurs only in restoring and while using target framework .NET 3.5.
.NET 4.0 and higher seem to have solved the issue, ...
2
votes
1
answer
478
views
How to mock IDataReader.NextResult?
I have a stored procedure which returns two resultsets. I process it like this in my production code:
Rdr = Cmd.ExecuteReader();
while (Rdr.Read())
{
// process first resultset
}
Rdr.NextResult();...
-1
votes
1
answer
44
views
sql(dr) is sending a missing result
I transfer the data I have taken from sql to the list, but it sends 1 missing data every time, the sql command works without any problems.
works incorrectly in c#
If there are 10 data in sql, it pulls ...
0
votes
1
answer
308
views
C# - SqlDataReader missing columns
Here is my records like in the table below.
sql query
My SQL query is
select Category_NM as 'Kategoriler', avg(Payment) as 'Ortalamalar'
from Islem
where Category_Type = 'Gider'
group by ...
0
votes
0
answers
62
views
C# Combining using statement with IAsyncReader
I'm looking to combine an async fill operation with disposable.
class G
{
SqlConnection connection
SqlCommand command;
IAyncResult Begin(string connectionString)
{
this....
0
votes
1
answer
1k
views
How to get multiple columns from one SQL query with SQLite and C#
I have an SQLite table that I want to get multiple columns at once. I use a query similar to this to this one to get the data from the table:
"SELECT LastName, FirstName, Age, Birthday FROM ...
0
votes
1
answer
65
views
Cannot implicitly convert System.Data.SqlClient.SqlDatReader to AdoControls.SqlDataReader
I'm learning ADO.Net and have been performing SQL commands on GridView. Today I started to learn the SqlDataReader In ADO.Net and when I try to Execute my Command and pass it to the SqlDataReader ...
0
votes
1
answer
478
views
SqlDataReader how to bind Inner join data to object
Currently I'm trying to combine two database tabels with a join
After that I looping through the reader and create an Appointment Object foreach row that returned from the query. That Appointment ...
1
vote
1
answer
140
views
Linq query С# ASP.NET Core
I'm executing a sql script using:
SqlCommand command = new SqlCommand(sqlQuery, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
if(reader.HasRows)
{
while(reader....
0
votes
1
answer
85
views
SqlDataReader is lost after posting request using RestSharp
I'm writing a Windows service. It periodically connects to a SQL database and looks for new records. I can read the SQL database without an issue and it gets the data using a SqlDataReader. I then ...
0
votes
0
answers
206
views
SqlDataReader and API
private void buttonSend_Click(object sender, EventArgs e)
{
object functionReturnValue = null;
using (System.Net.WebClient client = new System.Net.WebClient())
{
...
0
votes
1
answer
106
views
SqlDataReader and SqlCommand in C#
private void button1_Click(object sender, EventArgs e)
{
object functionReturnValue = null;
using (System.Net.WebClient client = new System.Net.WebClient())
{
System.Collections....
0
votes
0
answers
716
views
VB.NET How to use ExecuteReader well
Here is a code :
Private Sub ComboBoxQC1L1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBoxQC1L1.SelectedIndexChanged
Dim conn As New SqlConnection
If conn....
5
votes
4
answers
4k
views
How to access values by the column's name rather than with datareader.GetString(X)?
I have a Visual Basic application where I have a connection to a MS SQL database. I have code which defines a SqlDataReader, opens the connection, and executes the ExecuteReader() command. I use the ...
2
votes
2
answers
3k
views
How to get double value with SqlDataReader
I'm trying read data from sql database. When I run the code, it gives an error when it comes to where it should read data.
"System.InvalidCastException: Specified cast is not valid."
I get ...