Microsoft ADO.NET System.Data.SqlClient, contained in System.Data.dll, used for connecting to SQL Server from .NET applications.
Questions tagged [sqlclient]
501 questions
120
votes
3 answers
How to use SqlClient in ASP.NET Core?
I am trying to use SQLClient library in the ASP.net Core but cant seem to get it working. I found this article online advising how to setup but its not working for me: http://blog.developers.ba/using-classic-ado-net-in-asp-net-vnext/
I have a…

Rob
- 6,819
- 17
- 71
- 131
30
votes
11 answers
What is wrong with this code. Why can't I use SqlConnection?
I am 100% newbie to SQl and wanted to make a ConsoleApp with the use of database. I read some about it and tried. When I needed to make SqlConnection, my VS 2019 Preview showed me this
Severity Code Description Project File Line …

Redlik
- 439
- 1
- 4
- 6
22
votes
2 answers
System.Data.EntityException: The underlying provider failed on Commit
Using Entity Framework, I received a number of the following exceptions last night in one of my applications:
System.Data.EntityException: The underlying provider failed on Commit. --->
System.Data.SqlClient.SqlException: Timeout expired. The…

Randy
- 1,955
- 2
- 15
- 24
21
votes
6 answers
Unable to locate System.Data.SqlClient reference
I have a fresh Visual Studio 2017 Professional install. I'm building a quick POC Console application using .NET 4.7.1, and I'm unable to find the reference for System.Data.SqlClient.
I have scoured my system, and located 4 versions of…

Allan L
- 247
- 1
- 2
- 9
19
votes
8 answers
System.Data.IDbCommand and asynchronous execution?
System.Data.SqlClient.SqlCommand
has methods
BeginExecuteNonQuery
BeginExecuteReader
BeginExecuteXmlReader
and
EndExecuteNonQuery
EndExecuteReader
EndExecuteXmlReader
for asynchronous execution.
System.Data.IDbCommand
only…

Stefan Steiger
- 78,642
- 66
- 377
- 442
19
votes
4 answers
Could not load file or assembly error in .Net Standard 2.0 class library
I have a .NET Standard 2.0 class library project with installed Nuget package System.Data.SqlClient version 4.4.0 and a Windows Form .NET Framework 4.7 project that has a reference to that class library.
Installing the Nuget Package and building the…

sahar
- 1,769
- 3
- 13
- 14
19
votes
4 answers
How do I prevent a timeout error when executing a store procedure using a SqlCommand?
I have a C# program which runs a stored procedure. If I run the stored procedure from Microsoft sql server management studio, it works fine. It does take about 30 seconds to execute. However, if I try to run the same stored procedure from a C#…

oshirowanen
- 15,297
- 82
- 198
- 350
18
votes
2 answers
How to display database records in asp.net mvc view
Using ASP.NET MVC with C#, how do you pass some database records to a View and display them in table form?
I need to know how I can transfer/pass some rows of records from a database that have been returned to an SqlDataReader object and pass that…

doncadavona
- 7,162
- 9
- 41
- 54
17
votes
5 answers
dotnet ef update database : A connection was successfully established with the server, but then an error occurred during the login process
When I run dotnet ef update database I get this error:
A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate chain was issued by an…

Amirabbas Motamedi
- 321
- 1
- 2
- 9
17
votes
1 answer
Return value of ExecuteNonQuery after rollback
Assuming that we have a stored procedure that does like something this:
BEGIN TRANSACTION
UPDATE sometable SET aField = 0 WHERE anotherField = 1;
UPDATE sometable SET aField = 1 WHERE anotherField = 2;
ROLLBACK TRANSACTION;
And from…

coffeeyesplease
- 1,018
- 9
- 15
16
votes
6 answers
SqlCommand() ExecuteNonQuery() truncates command text
I'm building a custom db deployment utility, I need to read text files containing sql scripts and execute them against the database.
Pretty easy stuff, so far so good.
However I've encountered a snag, the contents of the file are read successfully…

H. Abraham Chavez
- 828
- 2
- 8
- 20
14
votes
12 answers
Exception: type initializer for 'system.data.sqlclient.sqlconnection'?
I couldn't figure out what is the problem for this exception.
The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception
First attempt: I was using the WCF Service to make some small application. It works just fine and I…

DucDigital
- 4,580
- 9
- 49
- 97
14
votes
3 answers
System.InvalidCastException: 'The SqlParameterCollection only accepts non-null SqlParameter type objects, not SqlParameter objects.'
I migrated my project from ASP.NET Core 2.2 to ASP.NET Core 3.0. Now I get this exception. In ASP.NET Core 2.2 it was using FromSql(); now it is using FromSqlRaw(). I am calling my procedure using Entity Framework Core.
SqlParameter Username = new…

Muhammad Aftab
- 1,098
- 8
- 19
14
votes
1 answer
Set custom default CommandTimeout for all new Command Objects
The default CommandTimeout value is 30 seconds. You can manually change the value on an instance of the command object by doing the following
Dim cmd As New System.Data.SqlClient.SqlCommand
cmd.CommandTimeout = 60
Is there a way to specify a…

KyleMit
- 30,350
- 66
- 462
- 664
12
votes
2 answers
'while' in async computation expression where the condition is async
I'm playing around with using SqlClient in F# and I'm having difficulty with using SqlDataReader.ReadAsync. I'm trying to do the F# equivalent of
while (await reader.ReadAsync) { ... }
What is the best way to do this in F#? Below is my full program.…

Jared Moore
- 3,765
- 26
- 31