-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathSqlConnection.xml
More file actions
2951 lines (2660 loc) · 242 KB
/
SqlConnection.xml
File metadata and controls
2951 lines (2660 loc) · 242 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<Type Name="SqlConnection" FullName="System.Data.SqlClient.SqlConnection">
<TypeSignature Language="C#" Value="public sealed class SqlConnection : System.Data.Common.DbConnection" FrameworkAlternate="netcore-1.0;netcore-1.1" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi sealed beforefieldinit SqlConnection extends System.Data.Common.DbConnection" FrameworkAlternate="netcore-1.0;netcore-1.1" />
<TypeSignature Language="DocId" Value="T:System.Data.SqlClient.SqlConnection" />
<TypeSignature Language="VB.NET" Value="Public NotInheritable Class SqlConnection
Inherits DbConnection" FrameworkAlternate="netcore-1.0;netcore-1.1" />
<TypeSignature Language="F#" Value="type SqlConnection = class
 inherit DbConnection" FrameworkAlternate="netcore-1.0;netcore-1.1" />
<TypeSignature Language="C++ CLI" Value="public ref class SqlConnection sealed : System::Data::Common::DbConnection" FrameworkAlternate="netcore-1.0;netcore-1.1" />
<TypeSignature Language="C#" Value="public sealed class SqlConnection : System.ComponentModel.Component, ICloneable, IDisposable, System.Data.IDbConnection" FrameworkAlternate="netframework-1.1" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi sealed beforefieldinit SqlConnection extends System.ComponentModel.Component implements class System.Data.IDbConnection, class System.ICloneable, class System.IDisposable" FrameworkAlternate="netframework-1.1" />
<TypeSignature Language="VB.NET" Value="Public NotInheritable Class SqlConnection
Inherits Component
Implements ICloneable, IDbConnection, IDisposable" FrameworkAlternate="netframework-1.1" />
<TypeSignature Language="F#" Value="type SqlConnection = class
 inherit Component
 interface IDbConnection
 interface IDisposable
 interface ICloneable" FrameworkAlternate="netframework-1.1" />
<TypeSignature Language="C++ CLI" Value="public ref class SqlConnection sealed : System::ComponentModel::Component, ICloneable, IDisposable, System::Data::IDbConnection" FrameworkAlternate="netframework-1.1" />
<TypeSignature Language="C#" Value="public sealed class SqlConnection : System.Data.Common.DbConnection, ICloneable" FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi sealed beforefieldinit SqlConnection extends System.Data.Common.DbConnection implements class System.ICloneable" FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1" />
<TypeSignature Language="VB.NET" Value="Public NotInheritable Class SqlConnection
Inherits DbConnection
Implements ICloneable" FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
<TypeSignature Language="F#" Value="type SqlConnection = class
 inherit DbConnection
 interface ICloneable" FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
<TypeSignature Language="C++ CLI" Value="public ref class SqlConnection sealed : System::Data::Common::DbConnection, ICloneable" FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi sealed SqlConnection extends System.Data.Common.DbConnection implements class System.ICloneable" FrameworkAlternate="netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.4.0.0</AssemblyVersion>
<AssemblyVersion>4.5.0.0</AssemblyVersion>
<AssemblyVersion>4.6.0.0</AssemblyVersion>
<AssemblyVersion>4.6.1.0</AssemblyVersion>
<AssemblyVersion>4.6.1.1</AssemblyVersion>
<AssemblyVersion>4.6.1.5</AssemblyVersion>
<AssemblyVersion>4.6.1.6</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Data.Common.DbConnection</BaseTypeName>
<BaseTypeName FrameworkAlternate="netframework-1.1">System.ComponentModel.Component</BaseTypeName>
</Base>
<Interfaces>
<Interface FrameworkAlternate="netframework-1.1">
<InterfaceName>System.Data.IDbConnection</InterfaceName>
</Interface>
<Interface FrameworkAlternate="netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1">
<InterfaceName>System.ICloneable</InterfaceName>
</Interface>
<Interface FrameworkAlternate="netframework-1.1">
<InterfaceName>System.IDisposable</InterfaceName>
</Interface>
</Interfaces>
<Attributes>
<Attribute FrameworkAlternate="netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1">
<AttributeName Language="C#">[System.ComponentModel.DefaultEvent("InfoMessage")]</AttributeName>
<AttributeName Language="F#">[<System.ComponentModel.DefaultEvent("InfoMessage")>]</AttributeName>
</Attribute>
</Attributes>
<Docs>
<summary>Represents a connection to a SQL Server database. This class cannot be inherited.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
A <xref:System.Data.SqlClient.SqlConnection> object represents a unique session to a SQL Server data source. With a client/server database system, it is equivalent to a network connection to the server. <xref:System.Data.SqlClient.SqlConnection> is used together with <xref:System.Data.SqlClient.SqlDataAdapter> and <xref:System.Data.SqlClient.SqlCommand> to increase performance when connecting to a Microsoft SQL Server database. For all third-party SQL Server products and other OLE DB-supported data sources, use <xref:System.Data.OleDb.OleDbConnection>.
When you create an instance of <xref:System.Data.SqlClient.SqlConnection>, all properties are set to their initial values. For a list of these values, see the <xref:System.Data.SqlClient.SqlConnection> constructor.
See <xref:System.Data.SqlClient.SqlConnection.ConnectionString%2A> for a list of the keywords in a connection string.
If the <xref:System.Data.SqlClient.SqlConnection> goes out of scope, it won't be closed. Therefore, you must explicitly close the connection by calling `Close` or `Dispose`. `Close` and `Dispose` are functionally equivalent. If the connection pooling value `Pooling` is set to `true` or `yes`, the underlying connection is returned back to the connection pool. On the other hand, if `Pooling` is set to `false` or `no`, the underlying connection to the server is actually closed.
> [!NOTE]
> Login and logout events will not be raised on the server when a connection is fetched from or returned to the connection pool, because the connection is not actually closed when it is returned to the connection pool. For more information, see [SQL Server Connection Pooling (ADO.NET)](/dotnet/framework/data/adonet/sql-server-connection-pooling).
To ensure that connections are always closed, open the connection inside of a `using` block, as shown in the following code fragment. Doing so ensures that the connection is automatically closed when the code exits the block.
```vb
Using connection As New SqlConnection(connectionString)
connection.Open()
' Do work here; connection closed on following line.
End Using
```
```csharp
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
// Do work here; connection closed on following line.
}
```
> [!NOTE]
> To deploy high-performance applications, you must use connection pooling. When you use the .NET Framework Data Provider for SQL Server, you do not have to enable connection pooling because the provider manages this automatically, although you can modify some settings. For more information, see [SQL Server Connection Pooling (ADO.NET)](/dotnet/framework/data/adonet/sql-server-connection-pooling).
If a <xref:System.Data.SqlClient.SqlException> is generated by the method executing a <xref:System.Data.SqlClient.SqlCommand>, the <xref:System.Data.SqlClient.SqlConnection> remains open when the severity level is 19 or less. When the severity level is 20 or greater, the server ordinarily closes the <xref:System.Data.SqlClient.SqlConnection>. However, the user can reopen the connection and continue.
An application that creates an instance of the <xref:System.Data.SqlClient.SqlConnection> object can require all direct and indirect callers to have sufficient permission to the code by setting declarative or imperative security demands. <xref:System.Data.SqlClient.SqlConnection> makes security demands using the <xref:System.Data.SqlClient.SqlClientPermission> object. Users can verify that their code has sufficient permissions by using the <xref:System.Data.SqlClient.SqlClientPermissionAttribute> object. Users and administrators can also use the [Caspol.exe (Code Access Security Policy Tool)](/dotnet/framework/tools/caspol-exe-code-access-security-policy-tool) to modify security policy at the machine, user, and enterprise levels. For more information, see [Security in .NET](/dotnet/standard/security/). For an example demonstrating how to use security demands, see [Code Access Security and ADO.NET](/dotnet/framework/data/adonet/code-access-security).
For more information about handling warning and informational messages from the server, see [Connection Events](/dotnet/framework/data/adonet/connection-events). For more information about SQL Server engine errors and error messages, see [Database Engine Events and Errors](/sql/relational-databases/errors-events/database-engine-events-and-errors).
> [!CAUTION]
> You can force TCP instead of shared memory. You can do that by prefixing tcp: to the server name in the connection string or you can use localhost.
## Examples
The following example creates a <xref:System.Data.SqlClient.SqlCommand> and a <xref:System.Data.SqlClient.SqlConnection>. The <xref:System.Data.SqlClient.SqlConnection> is opened and set as the <xref:System.Data.SqlClient.SqlCommand.Connection%2A> for the <xref:System.Data.SqlClient.SqlCommand>. The example then calls <xref:System.Data.SqlClient.SqlCommand.ExecuteNonQuery%2A>. To accomplish this, the <xref:System.Data.SqlClient.SqlCommand.ExecuteNonQuery%2A> is passed a SqlConnection and a query string that is a Transact-SQL INSERT statement. The connection is closed automatically when the code exits the using block.
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlCommand.ExecuteNonQuery Example/CS/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Data.SqlClient/SqlCommand/ExecuteNonQuery/source.vb" id="Snippet1":::
]]></format>
</remarks>
<related type="Article" href="/dotnet/framework/data/adonet/connecting-to-a-data-source">Connecting to a Data Source in ADO.NET</related>
<related type="Article" href="/dotnet/framework/data/adonet/sql/">SQL Server and ADO.NET</related>
<related type="Article" href="/dotnet/framework/data/adonet/ado-net-overview">ADO.NET Overview</related>
</Docs>
<Members>
<MemberGroup MemberName=".ctor">
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Initializes a new instance of the <see cref="T:System.Data.SqlClient.SqlConnection" /> class.</summary>
<related type="Article" href="/dotnet/framework/data/adonet/ado-net-overview">ADO.NET Overview</related>
</Docs>
</MemberGroup>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public SqlConnection ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.SqlClient.SqlConnection.#ctor" />
<MemberSignature Language="VB.NET" Value="Public Sub New ()" />
<MemberSignature Language="C++ CLI" Value="public:
 SqlConnection();" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Parameters />
<Docs>
<summary>Initializes a new instance of the <see cref="T:System.Data.SqlClient.SqlConnection" /> class.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
When a new instance of <xref:System.Data.SqlClient.SqlConnection> is created, the read/write properties are set to the following initial values unless they are specifically set using their associated keywords in the <xref:System.Data.SqlClient.SqlConnection.ConnectionString> property.
|Properties|Initial value|
|----------------|-------------------|
|<xref:System.Data.SqlClient.SqlConnection.ConnectionString%2A>|empty string ("")|
|<xref:System.Data.SqlClient.SqlConnection.ConnectionTimeout%2A>|15|
|<xref:System.Data.SqlClient.SqlConnection.Database%2A>|empty string ("")|
|<xref:System.Data.SqlClient.SqlConnection.DataSource%2A>|empty string ("")|
You can change the value for these properties only by using the <xref:System.Data.SqlClient.SqlConnection.ConnectionString> property. The <xref:System.Data.SqlClient.SqlConnectionStringBuilder> class provides functionality for creating and managing the contents of connection strings.
## Examples
The following example creates and opens a <xref:System.Data.SqlClient.SqlConnection>.
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlConnection.SqlConnection Example/CS/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Data.SqlClient/SqlConnection/.ctor/source.vb" id="Snippet1":::
]]></format>
</remarks>
<related type="Article" href="/dotnet/framework/data/adonet/connecting-to-a-data-source">Connecting to a Data Source in ADO.NET</related>
<related type="Article" href="/dotnet/framework/data/adonet/sql/">SQL Server and ADO.NET</related>
<related type="Article" href="/dotnet/framework/data/adonet/ado-net-overview">ADO.NET Overview</related>
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public SqlConnection (string connectionString);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(string connectionString) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.SqlClient.SqlConnection.#ctor(System.String)" />
<MemberSignature Language="VB.NET" Value="Public Sub New (connectionString As String)" />
<MemberSignature Language="F#" Value="new System.Data.SqlClient.SqlConnection : string -> System.Data.SqlClient.SqlConnection" Usage="new System.Data.SqlClient.SqlConnection connectionString" />
<MemberSignature Language="C++ CLI" Value="public:
 SqlConnection(System::String ^ connectionString);" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Parameters>
<Parameter Name="connectionString" Type="System.String" />
</Parameters>
<Docs>
<param name="connectionString">The connection used to open the SQL Server database.</param>
<summary>Initializes a new instance of the <see cref="T:System.Data.SqlClient.SqlConnection" /> class when given a string that contains the connection string.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
When a new instance of <xref:System.Data.SqlClient.SqlConnection> is created, the read/write properties are set to the following initial values unless they are specifically set using their associated keywords in the <xref:System.Data.SqlClient.SqlConnection.ConnectionString> property.
|Properties|Initial value|
|----------------|-------------------|
|<xref:System.Data.SqlClient.SqlConnection.ConnectionString%2A>| `connectionString` |
|<xref:System.Data.SqlClient.SqlConnection.ConnectionTimeout%2A>|15|
|<xref:System.Data.SqlClient.SqlConnection.Database%2A>|empty string ("")|
|<xref:System.Data.SqlClient.SqlConnection.DataSource%2A>|empty string ("")|
You can change the value for these properties only by using the <xref:System.Data.SqlClient.SqlConnection.ConnectionString> property. The <xref:System.Data.SqlClient.SqlConnection> class provides functionality for creating and managing the contents of connection strings.
## Examples
The following example creates and opens a <xref:System.Data.SqlClient.SqlConnection>.
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlConnection.SqlConnection1 Example/CS/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Data.SqlClient/SqlConnection/.ctor/source1.vb" id="Snippet1":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentException">The supplied connection string argument failed <see cref="T:System.Data.SqlClient.SqlConnection.ConnectionString" /> validation.</exception>
<related type="Article" href="/dotnet/framework/data/adonet/connecting-to-a-data-source">Connecting to a Data Source (ADO.NET)</related>
<related type="Article" href="/dotnet/framework/data/adonet/sql/">Using the .NET Framework Data Provider for SQL Server</related>
<related type="Article" href="/dotnet/framework/data/adonet/ado-net-overview">ADO.NET Overview</related>
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public SqlConnection (string connectionString, System.Data.SqlClient.SqlCredential credential);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(string connectionString, class System.Data.SqlClient.SqlCredential credential) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.SqlClient.SqlConnection.#ctor(System.String,System.Data.SqlClient.SqlCredential)" />
<MemberSignature Language="VB.NET" Value="Public Sub New (connectionString As String, credential As SqlCredential)" />
<MemberSignature Language="F#" Value="new System.Data.SqlClient.SqlConnection : string * System.Data.SqlClient.SqlCredential -> System.Data.SqlClient.SqlConnection" Usage="new System.Data.SqlClient.SqlConnection (connectionString, credential)" />
<MemberSignature Language="C++ CLI" Value="public:
 SqlConnection(System::String ^ connectionString, System::Data::SqlClient::SqlCredential ^ credential);" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.6.1.6</AssemblyVersion>
</AssemblyInfo>
<Parameters>
<Parameter Name="connectionString" Type="System.String" Index="0" FrameworkAlternate="net-10.0-pp;net-6.0-pp;net-7.0-pp;net-8.0-pp;net-9.0-pp;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0-pp" />
<Parameter Name="credential" Type="System.Data.SqlClient.SqlCredential" Index="1" FrameworkAlternate="net-10.0-pp;net-6.0-pp;net-7.0-pp;net-8.0-pp;net-9.0-pp;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0-pp" />
</Parameters>
<Docs>
<param name="connectionString">A connection string that does not use any of the following connection string keywords: <see langword="Integrated Security = true" />, <see langword="UserId" />, or <see langword="Password" />; or that does not use <see langword="ContextConnection = true" />.</param>
<param name="credential">A <see cref="T:System.Data.SqlClient.SqlCredential" /> object. If <paramref name="credential" /> is null, <see cref="M:System.Data.SqlClient.SqlConnection.#ctor(System.String,System.Data.SqlClient.SqlCredential)" /> is functionally equivalent to <see cref="M:System.Data.SqlClient.SqlConnection.#ctor(System.String)" />.</param>
<summary>Initializes a new instance of the <see cref="T:System.Data.SqlClient.SqlConnection" /> class given a connection string, that does not use <see langword="Integrated Security = true" /> and a <see cref="T:System.Data.SqlClient.SqlCredential" /> object that contains the user ID and password.</summary>
<remarks>To be added.</remarks>
<exception cref="T:System.ArgumentException">The supplied connection string argument failed <see cref="T:System.Data.SqlClient.SqlConnection.ConnectionString" /> validation.</exception>
<related type="Article" href="/dotnet/framework/data/adonet/ado-net-overview">ADO.NET Overview</related>
</Docs>
</Member>
<Member MemberName="AccessToken">
<MemberSignature Language="C#" Value="public string AccessToken { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance string AccessToken" />
<MemberSignature Language="DocId" Value="P:System.Data.SqlClient.SqlConnection.AccessToken" />
<MemberSignature Language="VB.NET" Value="Public Property AccessToken As String" />
<MemberSignature Language="F#" Value="member this.AccessToken : string with get, set" Usage="System.Data.SqlClient.SqlConnection.AccessToken" />
<MemberSignature Language="C++ CLI" Value="public:
 property System::String ^ AccessToken { System::String ^ get(); void set(System::String ^ value); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.6.1.6</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1">
<AttributeName Language="C#">[System.ComponentModel.Browsable(false)]</AttributeName>
<AttributeName Language="F#">[<System.ComponentModel.Browsable(false)>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1">
<AttributeName Language="C#">[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]</AttributeName>
<AttributeName Language="F#">[<System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets the access token for the connection.</summary>
<value>The access token for the connection.</value>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="BeginDbTransaction">
<MemberSignature Language="C#" Value="protected override System.Data.Common.DbTransaction BeginDbTransaction (System.Data.IsolationLevel isolationLevel);" />
<MemberSignature Language="ILAsm" Value=".method familyhidebysig virtual instance class System.Data.Common.DbTransaction BeginDbTransaction(valuetype System.Data.IsolationLevel isolationLevel) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.SqlClient.SqlConnection.BeginDbTransaction(System.Data.IsolationLevel)" />
<MemberSignature Language="VB.NET" Value="Protected Overrides Function BeginDbTransaction (isolationLevel As IsolationLevel) As DbTransaction" />
<MemberSignature Language="F#" Value="override this.BeginDbTransaction : System.Data.IsolationLevel -> System.Data.Common.DbTransaction" Usage="sqlConnection.BeginDbTransaction isolationLevel" />
<MemberSignature Language="C++ CLI" Value="protected:
 override System::Data::Common::DbTransaction ^ BeginDbTransaction(System::Data::IsolationLevel isolationLevel);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Data.Common.DbTransaction</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="isolationLevel" Type="System.Data.IsolationLevel" Index="0" FrameworkAlternate="netcore-1.0;netcore-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
</Parameters>
<Docs>
<param name="isolationLevel">To be added.</param>
<summary>To be added.</summary>
<returns>To be added.</returns>
<remarks>To be added.</remarks>
</Docs>
</Member>
<MemberGroup MemberName="BeginTransaction">
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Starts a database transaction.</summary>
<related type="Article" href="/dotnet/framework/data/adonet/ado-net-overview">ADO.NET Overview</related>
</Docs>
</MemberGroup>
<Member MemberName="BeginTransaction">
<MemberSignature Language="C#" Value="public System.Data.SqlClient.SqlTransaction BeginTransaction ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance class System.Data.SqlClient.SqlTransaction BeginTransaction() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.SqlClient.SqlConnection.BeginTransaction" />
<MemberSignature Language="VB.NET" Value="Public Function BeginTransaction () As SqlTransaction" />
<MemberSignature Language="F#" Value="override this.BeginTransaction : unit -> System.Data.SqlClient.SqlTransaction" Usage="sqlConnection.BeginTransaction " FrameworkAlternate="netcore-1.0;netcore-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
<MemberSignature Language="C++ CLI" Value="public:
 System::Data::SqlClient::SqlTransaction ^ BeginTransaction();" />
<MemberSignature Language="F#" Value="member this.BeginTransaction : unit -> System.Data.SqlClient.SqlTransaction" Usage="sqlConnection.BeginTransaction " FrameworkAlternate="netframework-1.1" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Data.SqlClient.SqlTransaction</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Starts a database transaction.</summary>
<returns>An object representing the new transaction.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This command maps to the SQL Server implementation of BEGIN TRANSACTION.
You must explicitly commit or roll back the transaction using the <xref:System.Data.SqlClient.SqlTransaction.Commit%2A> or <xref:System.Data.SqlClient.SqlTransaction.Rollback%2A> method. To make sure that the .NET Framework Data Provider for SQL Server transaction management model performs correctly, avoid using other transaction management models, such as the one provided by SQL Server.
> [!NOTE]
> If you do not specify an isolation level, the default isolation level is used. To specify an isolation level with the <xref:System.Data.SqlClient.SqlConnection.BeginTransaction%2A> method, use the overload that takes the `iso` parameter (<xref:System.Data.SqlClient.SqlConnection.BeginTransaction%2A>). The isolation level set for a transaction persists after the transaction is completed and until the connection is closed or disposed. Setting the isolation level to **Snapshot** in a database where the snapshot isolation level is not enabled does not throw an exception. The transaction will complete using the default isolation level.
> [!CAUTION]
> If a transaction is started and a level 16 or higher error occurs on the server, the transaction will not be rolled back until the <xref:System.Data.SqlClient.SqlDataReader.Read%2A> method is invoked. No exception is thrown on **ExecuteReader**.
> [!CAUTION]
> When your query returns a large amount of data and calls `BeginTransaction`, a <xref:System.Data.SqlClient.SqlException> is thrown because SQL Server does not allow parallel transactions when using MARS. To avoid this problem, always associate a transaction with the command, the connection, or both before any readers are open.
For more information on SQL Server transactions, see [Transactions (Transact-SQL)](/sql/t-sql/language-elements/transactions-transact-sql).
## Examples
The following example creates a <xref:System.Data.SqlClient.SqlConnection> and a <xref:System.Data.SqlClient.SqlTransaction>. It also demonstrates how to use the <xref:System.Data.SqlClient.SqlConnection.BeginTransaction%2A>, a <xref:System.Data.SqlClient.SqlTransaction.Commit%2A>, and <xref:System.Data.SqlClient.SqlTransaction.Rollback%2A> methods.
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlConnection.BeginTransaction Example/CS/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Data/IDbTransaction/Overview/source.vb" id="Snippet1":::
]]></format>
</remarks>
<exception cref="T:System.Data.SqlClient.SqlException">Parallel transactions are not allowed when using Multiple Active Result Sets (MARS).</exception>
<exception cref="T:System.InvalidOperationException">Parallel transactions are not supported.</exception>
<related type="Article" href="/dotnet/framework/data/adonet/transactions-and-concurrency">Transactions and Concurrency</related>
<related type="Article" href="/dotnet/framework/data/adonet/connecting-to-a-data-source">Connecting to a Data Source in ADO.NET</related>
<related type="Article" href="/dotnet/framework/data/adonet/sql/">SQL Server and ADO.NET</related>
<related type="Article" href="/dotnet/framework/data/adonet/ado-net-overview">ADO.NET Overview</related>
</Docs>
</Member>
<Member MemberName="BeginTransaction">
<MemberSignature Language="C#" Value="public System.Data.SqlClient.SqlTransaction BeginTransaction (System.Data.IsolationLevel iso);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance class System.Data.SqlClient.SqlTransaction BeginTransaction(valuetype System.Data.IsolationLevel iso) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.SqlClient.SqlConnection.BeginTransaction(System.Data.IsolationLevel)" />
<MemberSignature Language="VB.NET" Value="Public Function BeginTransaction (iso As IsolationLevel) As SqlTransaction" />
<MemberSignature Language="F#" Value="override this.BeginTransaction : System.Data.IsolationLevel -> System.Data.SqlClient.SqlTransaction" Usage="sqlConnection.BeginTransaction iso" FrameworkAlternate="netcore-1.0;netcore-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
<MemberSignature Language="C++ CLI" Value="public:
 System::Data::SqlClient::SqlTransaction ^ BeginTransaction(System::Data::IsolationLevel iso);" />
<MemberSignature Language="F#" Value="member this.BeginTransaction : System.Data.IsolationLevel -> System.Data.SqlClient.SqlTransaction" Usage="sqlConnection.BeginTransaction iso" FrameworkAlternate="netframework-1.1" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Data.SqlClient.SqlTransaction</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="iso" Type="System.Data.IsolationLevel" />
</Parameters>
<Docs>
<param name="iso">The isolation level under which the transaction should run.</param>
<summary>Starts a database transaction with the specified isolation level.</summary>
<returns>An object representing the new transaction.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This command maps to the SQL Server implementation of BEGIN TRANSACTION.
You must explicitly commit or roll back the transaction using the <xref:System.Data.SqlClient.SqlTransaction.Commit%2A> or <xref:System.Data.SqlClient.SqlTransaction.Rollback%2A> method. To make sure that the .NET Framework Data Provider for SQL Server transaction management model performs correctly, avoid using other transaction management models, such as the one provided by SQL Server.
> [!NOTE]
> After a transaction is committed or rolled back, the isolation level of the transaction persists for all subsequent commands that are in autocommit mode (the SQL Server default). This can produce unexpected results, such as an isolation level of REPEATABLE READ persisting and locking other users out of a row. To reset the isolation level to the default (READ COMMITTED), execute the Transact-SQL SET TRANSACTION ISOLATION LEVEL READ COMMITTED statement, or call <xref:System.Data.SqlClient.SqlConnection.BeginTransaction%2A?displayProperty=nameWithType> followed immediately by <xref:System.Data.SqlClient.SqlTransaction.Commit%2A?displayProperty=nameWithType>. For more information on SQL Server isolation levels, see [Transaction Isolation Levels](/sql/t-sql/language-elements/transaction-isolation-levels).
For more information on SQL Server transactions, see [Transactions (Transact-SQL)](/sql/t-sql/language-elements/transactions-transact-sql).
> [!CAUTION]
> When your query returns a large amount of data and calls `BeginTransaction`, a <xref:System.Data.SqlClient.SqlException> is thrown because SQL Server does not allow parallel transactions when using MARS. To avoid this problem, always associate a transaction with the command, the connection, or both before any readers are open.
## Examples
The following example creates a <xref:System.Data.SqlClient.SqlConnection> and a <xref:System.Data.SqlClient.SqlTransaction>. It also demonstrates how to use the <xref:System.Data.SqlClient.SqlConnection.BeginTransaction%2A>, a <xref:System.Data.SqlClient.SqlTransaction.Commit%2A>, and <xref:System.Data.SqlClient.SqlTransaction.Rollback%2A> methods.
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlConnection.BeginTransaction1 Example/CS/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Data.SqlClient/SqlConnection/BeginTransaction/source.vb" id="Snippet1":::
]]></format>
</remarks>
<exception cref="T:System.Data.SqlClient.SqlException">Parallel transactions are not allowed when using Multiple Active Result Sets (MARS).</exception>
<exception cref="T:System.InvalidOperationException">Parallel transactions are not supported.</exception>
<related type="Article" href="/dotnet/framework/data/adonet/transactions-and-concurrency">Transactions (ADO.NET)</related>
<related type="Article" href="/dotnet/framework/data/adonet/connecting-to-a-data-source">Connecting to a Data Source (ADO.NET)</related>
<related type="Article" href="/dotnet/framework/data/adonet/sql/">Using the .NET Framework Data Provider for SQL Server</related>
<related type="Article" href="/dotnet/framework/data/adonet/ado-net-overview">ADO.NET Overview</related>
</Docs>
</Member>
<Member MemberName="BeginTransaction">
<MemberSignature Language="C#" Value="public System.Data.SqlClient.SqlTransaction BeginTransaction (string transactionName);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance class System.Data.SqlClient.SqlTransaction BeginTransaction(string transactionName) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.SqlClient.SqlConnection.BeginTransaction(System.String)" />
<MemberSignature Language="VB.NET" Value="Public Function BeginTransaction (transactionName As String) As SqlTransaction" />
<MemberSignature Language="F#" Value="override this.BeginTransaction : string -> System.Data.SqlClient.SqlTransaction" Usage="sqlConnection.BeginTransaction transactionName" FrameworkAlternate="netcore-1.0;netcore-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
<MemberSignature Language="C++ CLI" Value="public:
 System::Data::SqlClient::SqlTransaction ^ BeginTransaction(System::String ^ transactionName);" />
<MemberSignature Language="F#" Value="member this.BeginTransaction : string -> System.Data.SqlClient.SqlTransaction" Usage="sqlConnection.BeginTransaction transactionName" FrameworkAlternate="netframework-1.1" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Data.SqlClient.SqlTransaction</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="transactionName" Type="System.String" />
</Parameters>
<Docs>
<param name="transactionName">The name of the transaction.</param>
<summary>Starts a database transaction with the specified transaction name.</summary>
<returns>An object representing the new transaction.</returns>
<remarks>
<format type="text/markdown"><.
> [!CAUTION]
> When your query returns a large amount of data and calls `BeginTransaction`, a <xref:System.Data.SqlClient.SqlException> is thrown because SQL Server does not allow parallel transactions when using MARS. To avoid this problem, always associate a transaction with the command, the connection, or both before any readers are open.
## Examples
The following example creates a <xref:System.Data.SqlClient.SqlConnection> and a <xref:System.Data.SqlClient.SqlTransaction>. It also demonstrates how to use the <xref:System.Data.SqlClient.SqlConnection.BeginTransaction%2A>, a <xref:System.Data.SqlClient.SqlTransaction.Commit%2A>, and <xref:System.Data.SqlClient.SqlTransaction.Rollback%2A> methods.
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlConnection.BeginTransaction2 Example/CS/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Data.SqlClient/SqlConnection/BeginTransaction/source1.vb" id="Snippet1":::
]]></format>
</remarks>
<exception cref="T:System.Data.SqlClient.SqlException">Parallel transactions are not allowed when using Multiple Active Result Sets (MARS).</exception>
<exception cref="T:System.InvalidOperationException">Parallel transactions are not supported.</exception>
<related type="Article" href="/dotnet/framework/data/adonet/transactions-and-concurrency">Transactions (ADO.NET)</related>
<related type="Article" href="/dotnet/framework/data/adonet/connecting-to-a-data-source">Connecting to a Data Source (ADO.NET)</related>
<related type="Article" href="/dotnet/framework/data/adonet/sql/">Using the .NET Framework Data Provider for SQL Server</related>
<related type="Article" href="/dotnet/framework/data/adonet/ado-net-overview">ADO.NET Overview</related>
</Docs>
</Member>
<Member MemberName="BeginTransaction">
<MemberSignature Language="C#" Value="public System.Data.SqlClient.SqlTransaction BeginTransaction (System.Data.IsolationLevel iso, string transactionName);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance class System.Data.SqlClient.SqlTransaction BeginTransaction(valuetype System.Data.IsolationLevel iso, string transactionName) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.SqlClient.SqlConnection.BeginTransaction(System.Data.IsolationLevel,System.String)" />
<MemberSignature Language="VB.NET" Value="Public Function BeginTransaction (iso As IsolationLevel, transactionName As String) As SqlTransaction" />
<MemberSignature Language="F#" Value="override this.BeginTransaction : System.Data.IsolationLevel * string -> System.Data.SqlClient.SqlTransaction" Usage="sqlConnection.BeginTransaction (iso, transactionName)" FrameworkAlternate="netcore-1.0;netcore-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
<MemberSignature Language="C++ CLI" Value="public:
 System::Data::SqlClient::SqlTransaction ^ BeginTransaction(System::Data::IsolationLevel iso, System::String ^ transactionName);" />
<MemberSignature Language="F#" Value="member this.BeginTransaction : System.Data.IsolationLevel * string -> System.Data.SqlClient.SqlTransaction" Usage="sqlConnection.BeginTransaction (iso, transactionName)" FrameworkAlternate="netframework-1.1" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Data.SqlClient.SqlTransaction</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="iso" Type="System.Data.IsolationLevel" />
<Parameter Name="transactionName" Type="System.String" />
</Parameters>
<Docs>
<param name="iso">The isolation level under which the transaction should run.</param>
<param name="transactionName">The name of the transaction.</param>
<summary>Starts a database transaction with the specified isolation level and transaction name.</summary>
<returns>An object representing the new transaction.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This command maps to the SQL Server implementation of BEGIN TRANSACTION.
The value in the `transactionName` parameter can be used in later calls to <xref:System.Data.SqlClient.SqlTransaction.Rollback%2A> and in the `savePoint` parameter of the <xref:System.Data.SqlClient.SqlTransaction.Save%2A> method.
You must explicitly commit or roll back the transaction using the <xref:System.Data.SqlClient.SqlTransaction.Commit%2A> or <xref:System.Data.SqlClient.SqlTransaction.Rollback%2A> method. To make sure that the SQL Server transaction management model performs correctly, avoid using other transaction management models, such as the one provided by SQL Server.
> [!NOTE]
> After a transaction is committed or rolled back, the isolation level of the transaction persists for all subsequent commands that are in autocommit mode (the SQL Server default). This can produce unexpected results, such as an isolation level of REPEATABLE READ persisting and locking other users out of a row. To reset the isolation level to the default (READ COMMITTED), execute the Transact-SQL SET TRANSACTION ISOLATION LEVEL READ COMMITTED statement, or call <xref:System.Data.SqlClient.SqlConnection.BeginTransaction%2A?displayProperty=nameWithType> followed immediately by <xref:System.Data.SqlClient.SqlTransaction.Commit%2A?displayProperty=nameWithType>. For more information on SQL Server isolation levels, see [Transaction Isolation Levels](/sql/t-sql/language-elements/transaction-isolation-levels).
For more information on SQL Server transactions, see [Transactions (Transact-SQL)](/sql/t-sql/language-elements/transactions-transact-sql).
> [!CAUTION]
> When your query returns a large amount of data and calls `BeginTransaction`, a <xref:System.Data.SqlClient.SqlException> is thrown because SQL Server does not allow parallel transactions when using MARS. To avoid this problem, always associate a transaction with the command, the connection, or both before any readers are open.
## Examples
The following example creates a <xref:System.Data.SqlClient.SqlConnection> and a <xref:System.Data.SqlClient.SqlTransaction>. It also demonstrates how to use the <xref:System.Data.SqlClient.SqlConnection.BeginTransaction%2A>, a <xref:System.Data.SqlClient.SqlTransaction.Commit%2A>, and <xref:System.Data.SqlClient.SqlTransaction.Rollback%2A> methods.
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlConnection.BeginTransaction3 Example/CS/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Data.SqlClient/SqlConnection/BeginTransaction/source2.vb" id="Snippet1":::
]]></format>
</remarks>
<exception cref="T:System.Data.SqlClient.SqlException">Parallel transactions are not allowed when using Multiple Active Result Sets (MARS).</exception>
<exception cref="T:System.InvalidOperationException">Parallel transactions are not supported.</exception>
<related type="Article" href="/dotnet/framework/data/adonet/transactions-and-concurrency">Transactions (ADO.NET)</related>
<related type="Article" href="/dotnet/framework/data/adonet/connecting-to-a-data-source">Connecting to a Data Source (ADO.NET)</related>
<related type="Article" href="/dotnet/framework/data/adonet/sql/">Using the .NET Framework Data Provider for SQL Server</related>
<related type="Article" href="/dotnet/framework/data/adonet/ado-net-overview">ADO.NET Overview</related>
</Docs>
</Member>
<Member MemberName="ChangeDatabase">
<MemberSignature Language="C#" Value="public override void ChangeDatabase (string database);" FrameworkAlternate="netcore-1.0;netcore-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance void ChangeDatabase(string database) cil managed" FrameworkAlternate="netcore-1.0;netcore-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
<MemberSignature Language="DocId" Value="M:System.Data.SqlClient.SqlConnection.ChangeDatabase(System.String)" />
<MemberSignature Language="VB.NET" Value="Public Overrides Sub ChangeDatabase (database As String)" FrameworkAlternate="netcore-1.0;netcore-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
<MemberSignature Language="F#" Value="override this.ChangeDatabase : string -> unit" Usage="sqlConnection.ChangeDatabase database" FrameworkAlternate="netcore-1.0;netcore-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
<MemberSignature Language="C++ CLI" Value="public:
 override void ChangeDatabase(System::String ^ database);" FrameworkAlternate="netcore-1.0;netcore-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
<MemberSignature Language="C#" Value="public void ChangeDatabase (string database);" FrameworkAlternate="netframework-1.1" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance void ChangeDatabase(string database) cil managed" FrameworkAlternate="netframework-1.1" />
<MemberSignature Language="VB.NET" Value="Public Sub ChangeDatabase (database As String)" FrameworkAlternate="netframework-1.1" />
<MemberSignature Language="F#" Value="abstract member ChangeDatabase : string -> unit
override this.ChangeDatabase : string -> unit" Usage="sqlConnection.ChangeDatabase database" FrameworkAlternate="netframework-1.1" />
<MemberSignature Language="C++ CLI" Value="public:
 virtual void ChangeDatabase(System::String ^ database);" FrameworkAlternate="netframework-1.1" />
<MemberType>Method</MemberType>
<Implements>
<InterfaceMember FrameworkAlternate="netframework-1.1">M:System.Data.IDbConnection.ChangeDatabase(System.String)</InterfaceMember>
</Implements>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="database" Type="System.String" />
</Parameters>
<Docs>
<param name="database">The name of the database to use instead of the current database.</param>
<summary>Changes the current database for an open <see cref="T:System.Data.SqlClient.SqlConnection" />.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The value supplied in the `database` parameter must be a valid database name. The `database` parameter cannot contain a null value, an empty string, or a string with only blank characters.
## Examples
The following example creates a <xref:System.Data.SqlClient.SqlConnection> and displays some of its read-only properties.
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlConnection.Database Example/CS/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Data.SqlClient/SqlConnection/ChangeDatabase/source.vb" id="Snippet1":::
]]></format>
</remarks>
<exception cref="T:System.ArgumentException">The database name is not valid.</exception>
<exception cref="T:System.InvalidOperationException">The connection is not open.</exception>
<exception cref="T:System.Data.SqlClient.SqlException">Cannot change the database.</exception>
<related type="Article" href="/dotnet/framework/data/adonet/connecting-to-a-data-source">Connecting to a Data Source in ADO.NET</related>
<related type="Article" href="/dotnet/framework/data/adonet/sql/">SQL Server and ADO.NET</related>
<related type="Article" href="/dotnet/framework/data/adonet/ado-net-overview">ADO.NET Overview</related>
</Docs>
</Member>
<MemberGroup MemberName="ChangePassword">
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Changes the SQL Server password.</summary>
<related type="Article" href="/dotnet/framework/data/adonet/ado-net-overview">ADO.NET Overview</related>
</Docs>
</MemberGroup>
<Member MemberName="ChangePassword">
<MemberSignature Language="C#" Value="public static void ChangePassword (string connectionString, string newPassword);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig void ChangePassword(string connectionString, string newPassword) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.SqlClient.SqlConnection.ChangePassword(System.String,System.String)" />
<MemberSignature Language="VB.NET" Value="Public Shared Sub ChangePassword (connectionString As String, newPassword As String)" />
<MemberSignature Language="F#" Value="static member ChangePassword : string * string -> unit" Usage="System.Data.SqlClient.SqlConnection.ChangePassword (connectionString, newPassword)" />
<MemberSignature Language="C++ CLI" Value="public:
 static void ChangePassword(System::String ^ connectionString, System::String ^ newPassword);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.6.1.6</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="connectionString" Type="System.String" Index="0" FrameworkAlternate="net-10.0-pp;net-6.0-pp;net-7.0-pp;net-8.0-pp;net-9.0-pp;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0-pp" />
<Parameter Name="newPassword" Type="System.String" Index="1" FrameworkAlternate="net-10.0-pp;net-6.0-pp;net-7.0-pp;net-8.0-pp;net-9.0-pp;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0-pp" />
</Parameters>
<Docs>
<param name="connectionString">The connection string that contains enough information to connect to the server that you want. The connection string must contain the user ID and the current password.</param>
<param name="newPassword">The new password to set. This password must comply with any password security policy set on the server, including minimum length, requirements for specific characters, and so on.</param>
<summary>Changes the SQL Server password for the user indicated in the connection string to the specified new password.</summary>
<remarks>
<format type="text/markdown"><]
The <xref:System.Data.SqlClient.SqlConnection.ChangePassword%2A> method changes the SQL Server password for the user indicated in the supplied `connectionString` parameter to the value supplied in the `newPassword` parameter. If the connection string includes the option for integrated security (that is, "Integrated Security=True" or the equivalent), an exception is thrown.
To determine that the password has expired, calling the <xref:System.Data.SqlClient.SqlConnection.Open%2A> method raises a <xref:System.Data.SqlClient.SqlException>. In order to indicate that the password that is contained within the connection string must be reset, the <xref:System.Data.SqlClient.SqlException.Number> property for the exception contains the status value 18487 or 18488. The first value (18487) indicates that the password has expired and the second (18488) indicates that the password must be reset before logging in.
This method opens its own connection to the server, requests the password change, and closes the connection as soon as it has completed. This connection is not retrieved from or returned to the SQL Server connection pool.
]]></format>
</remarks>
<exception cref="T:System.ArgumentException">The connection string includes the option to use integrated security.
Or
The <paramref name="newPassword" /> exceeds 128 characters.</exception>
<exception cref="T:System.ArgumentNullException">Either the <paramref name="connectionString" /> or the <paramref name="newPassword" /> parameter is null.</exception>
<related type="Article" href="/dotnet/framework/data/adonet/connection-strings">Connection Strings (ADO.NET)</related>
<related type="Article" href="/dotnet/framework/data/adonet/connecting-to-a-data-source">Connecting to a Data Source (ADO.NET)</related>
<related type="Article" href="/dotnet/framework/data/adonet/sql/">Using the .NET Framework Data Provider for SQL Server</related>
<related type="Article" href="/dotnet/framework/data/adonet/ado-net-overview">ADO.NET Overview</related>
</Docs>
</Member>
<Member MemberName="ChangePassword">
<MemberSignature Language="C#" Value="public static void ChangePassword (string connectionString, System.Data.SqlClient.SqlCredential credential, System.Security.SecureString newSecurePassword);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig void ChangePassword(string connectionString, class System.Data.SqlClient.SqlCredential credential, class System.Security.SecureString newSecurePassword) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.SqlClient.SqlConnection.ChangePassword(System.String,System.Data.SqlClient.SqlCredential,System.Security.SecureString)" />
<MemberSignature Language="VB.NET" Value="Public Shared Sub ChangePassword (connectionString As String, credential As SqlCredential, newSecurePassword As SecureString)" />
<MemberSignature Language="F#" Value="static member ChangePassword : string * System.Data.SqlClient.SqlCredential * System.Security.SecureString -> unit" Usage="System.Data.SqlClient.SqlConnection.ChangePassword (connectionString, credential, newSecurePassword)" />
<MemberSignature Language="C++ CLI" Value="public:
 static void ChangePassword(System::String ^ connectionString, System::Data::SqlClient::SqlCredential ^ credential, System::Security::SecureString ^ newSecurePassword);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.6.1.6</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="connectionString" Type="System.String" Index="0" FrameworkAlternate="net-10.0-pp;net-6.0-pp;net-7.0-pp;net-8.0-pp;net-9.0-pp;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0-pp" />
<Parameter Name="credential" Type="System.Data.SqlClient.SqlCredential" Index="1" FrameworkAlternate="net-10.0-pp;net-6.0-pp;net-7.0-pp;net-8.0-pp;net-9.0-pp;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0-pp" />
<Parameter Name="newPassword" Type="System.Security.SecureString" Index="2" FrameworkAlternate="net-10.0-pp;net-6.0-pp;net-7.0-pp;net-8.0-pp;net-9.0-pp;netstandard-2.0-pp" />
<Parameter Name="newSecurePassword" Type="System.Security.SecureString" Index="2" FrameworkAlternate="netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
</Parameters>
<Docs>
<param name="connectionString">The connection string that contains enough information to connect to a server. The connection string should not use any of the following connection string keywords: <see langword="Integrated Security = true" />, <see langword="UserId" />, or <see langword="Password" />; or <see langword="ContextConnection = true" />.</param>
<param name="credential">A <see cref="T:System.Data.SqlClient.SqlCredential" /> object.</param>
<param name="newPassword">The new password.<paramref name="newPassword" /> must be read only. The password must also comply with any password security policy set on the server (for example, minimum length and requirements for specific characters).</param>
<param name="newSecurePassword">The new password. <paramref name="newSecurePassword" /> must be read only. The password must also comply with any password security policy set on the server (for example, minimum length and requirements for specific characters).</param>
<summary>Changes the SQL Server password for the user indicated in the <see cref="T:System.Data.SqlClient.SqlCredential" /> object.</summary>
<remarks>To be added.</remarks>
<exception cref="T:System.ArgumentException">The connection string contains any combination of <see langword="UserId" />, <see langword="Password" />, or <see langword="Integrated Security=true" />.
-or-
The connection string contains <see langword="Context Connection=true" />.
-or-
<paramref name="newSecurePassword" /> (or <paramref name="newPassword" />) is greater than 128 characters.
-or-
<paramref name="newSecurePassword" /> (or <paramref name="newPassword" />) is not read only.
-or-
<paramref name="newSecurePassword" /> (or <paramref name="newPassword" />) is an empty string.</exception>
<exception cref="T:System.ArgumentNullException">One of the parameters (<paramref name="connectionString" />, <paramref name="credential" />, or <paramref name="newSecurePassword" />) is null.</exception>
<related type="Article" href="/dotnet/framework/data/adonet/ado-net-overview">ADO.NET Overview</related>
</Docs>
</Member>
<Member MemberName="ClearAllPools">
<MemberSignature Language="C#" Value="public static void ClearAllPools ();" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig void ClearAllPools() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.SqlClient.SqlConnection.ClearAllPools" />
<MemberSignature Language="VB.NET" Value="Public Shared Sub ClearAllPools ()" />
<MemberSignature Language="F#" Value="static member ClearAllPools : unit -> unit" Usage="System.Data.SqlClient.SqlConnection.ClearAllPools " />
<MemberSignature Language="C++ CLI" Value="public:
 static void ClearAllPools();" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Empties the connection pool.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
<xref:System.Data.SqlClient.SqlConnection.ClearAllPools%2A> resets (or empties) the connection pool. If there are connections in use at the time of the call, they are marked appropriately and will be discarded (instead of being returned to the pool) when <xref:System.Data.SqlClient.SqlConnection.Close%2A> is called on them.
]]></format>
</remarks>
<related type="Article" href="/dotnet/framework/data/adonet/sql-server-connection-pooling">SQL Server Connection Pooling (ADO.NET)</related>
<related type="Article" href="/dotnet/framework/data/adonet/ado-net-overview">ADO.NET Overview</related>
</Docs>
</Member>
<Member MemberName="ClearPool">
<MemberSignature Language="C#" Value="public static void ClearPool (System.Data.SqlClient.SqlConnection connection);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig void ClearPool(class System.Data.SqlClient.SqlConnection connection) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.SqlClient.SqlConnection.ClearPool(System.Data.SqlClient.SqlConnection)" />
<MemberSignature Language="VB.NET" Value="Public Shared Sub ClearPool (connection As SqlConnection)" />
<MemberSignature Language="F#" Value="static member ClearPool : System.Data.SqlClient.SqlConnection -> unit" Usage="System.Data.SqlClient.SqlConnection.ClearPool connection" />
<MemberSignature Language="C++ CLI" Value="public:
 static void ClearPool(System::Data::SqlClient::SqlConnection ^ connection);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="connection" Type="System.Data.SqlClient.SqlConnection" Index="0" FrameworkAlternate="netcore-1.0;netcore-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
</Parameters>
<Docs>
<param name="connection">The <see cref="T:System.Data.SqlClient.SqlConnection" /> to be cleared from the pool.</param>
<summary>Empties the connection pool associated with the specified connection.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
<xref:System.Data.SqlClient.SqlConnection.ClearPool%2A> clears the connection pool that is associated with the `connection`. If additional connections associated with `connection` are in use at the time of the call, they are marked appropriately and are discarded (instead of being returned to the pool) when <xref:System.Data.SqlClient.SqlConnection.Close%2A> is called on them.
]]></format>
</remarks>
<related type="Article" href="/dotnet/framework/data/adonet/sql-server-connection-pooling">SQL Server Connection Pooling (ADO.NET)</related>
<related type="Article" href="/dotnet/framework/data/adonet/ado-net-overview">ADO.NET Overview</related>
</Docs>
</Member>
<Member MemberName="ClientConnectionId">
<MemberSignature Language="C#" Value="public Guid ClientConnectionId { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance valuetype System.Guid ClientConnectionId" />
<MemberSignature Language="DocId" Value="P:System.Data.SqlClient.SqlConnection.ClientConnectionId" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property ClientConnectionId As Guid" />
<MemberSignature Language="F#" Value="member this.ClientConnectionId : Guid" Usage="System.Data.SqlClient.SqlConnection.ClientConnectionId" />
<MemberSignature Language="C++ CLI" Value="public:
 property Guid ClientConnectionId { Guid get(); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1">
<AttributeName Language="C#">[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]</AttributeName>
<AttributeName Language="F#">[<System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Guid</ReturnType>
</ReturnValue>
<Docs>
<summary>The connection ID of the most recent connection attempt, regardless of whether the attempt succeeded or failed.</summary>
<value>The connection ID of the most recent connection attempt.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
<xref:System.Data.SqlClient.SqlConnection.ClientConnectionId%2A> works regardless of which version of the server you connect to, but extended events logs and entry on connectivity ring buffer errors will not be present in SQL Server 2008 R2 and earlier.
You can locate the connection ID in the extended events log to see if the failure was on the server if the extended event for logging connection ID is enabled. You can also locate the connection ID in the connection ring buffer for certain connection errors. If the connection ID is not in the connection ring buffer, you can assume a network error.
]]></format>
</remarks>
<related type="Article" href="/dotnet/framework/data/adonet/ado-net-overview">ADO.NET Overview</related>
</Docs>
</Member>
<Member MemberName="Close">
<MemberSignature Language="C#" Value="public override void Close ();" FrameworkAlternate="netcore-1.0;netcore-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance void Close() cil managed" FrameworkAlternate="netcore-1.0;netcore-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
<MemberSignature Language="DocId" Value="M:System.Data.SqlClient.SqlConnection.Close" />
<MemberSignature Language="VB.NET" Value="Public Overrides Sub Close ()" FrameworkAlternate="netcore-1.0;netcore-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
<MemberSignature Language="F#" Value="override this.Close : unit -> unit" Usage="sqlConnection.Close " FrameworkAlternate="netcore-1.0;netcore-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
<MemberSignature Language="C++ CLI" Value="public:
 override void Close();" FrameworkAlternate="netcore-1.0;netcore-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
<MemberSignature Language="C#" Value="public void Close ();" FrameworkAlternate="netframework-1.1" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance void Close() cil managed" FrameworkAlternate="netframework-1.1" />
<MemberSignature Language="VB.NET" Value="Public Sub Close ()" FrameworkAlternate="netframework-1.1" />
<MemberSignature Language="F#" Value="abstract member Close : unit -> unit
override this.Close : unit -> unit" Usage="sqlConnection.Close " FrameworkAlternate="netframework-1.1" />
<MemberSignature Language="C++ CLI" Value="public:
 virtual void Close();" FrameworkAlternate="netframework-1.1" />
<MemberType>Method</MemberType>
<Implements>
<InterfaceMember FrameworkAlternate="netframework-1.1">M:System.Data.IDbConnection.Close</InterfaceMember>
</Implements>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Closes the connection to the database. This is the preferred method of closing any open connection.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Data.SqlClient.SqlConnection.Close%2A> method rolls back any pending transactions. It then releases the connection to the connection pool, or closes the connection if connection pooling is disabled.
> [!NOTE]
> Pending transactions started using Transact-SQL or <xref:System.Data.SqlClient.SqlConnection.BeginTransaction%2A> are automatically rolled back when the connection is reset if connection pooling is enabled. If connection pooling is off, the transaction is rolled back after `SqlConnection.Close` is called. Transactions started through <xref:System.Transactions> are controlled through the `System.Transactions` infrastructure, and are not affected by `SqlConnection.Close`.
An application can call <xref:System.Data.SqlClient.SqlConnection.Close%2A> more than one time. No exception is generated.
If the <xref:System.Data.SqlClient.SqlConnection> goes out of scope, it won't be closed. Therefore, you must explicitly close the connection by calling `Close` or `Dispose`. `Close` and `Dispose` are functionally equivalent. If the connection pooling value `Pooling` is set to `true` or `yes`, the underlying connection is returned back to the connection pool. On the other hand, if `Pooling` is set to `false` or `no`, the underlying connection to the server is closed.
> [!NOTE]
> Login and logout events will not be raised on the server when a connection is fetched from or returned to the connection pool, because the connection is not actually closed when it is returned to the connection pool. For more information, see [SQL Server Connection Pooling (ADO.NET)](/dotnet/framework/data/adonet/sql-server-connection-pooling).
> [!CAUTION]
> Do not call `Close` or `Dispose` on a Connection, a DataReader, or any other managed object in the `Finalize` method of your class. In a finalizer, you should only release unmanaged resources that your class owns directly. If your class does not own any unmanaged resources, do not include a `Finalize` method in your class definition. For more information, see [Garbage Collection](/dotnet/standard/garbage-collection/).
## Examples
The following example creates a <xref:System.Data.SqlClient.SqlConnection>, opens it, displays some of its properties. The connection is automatically closed at the end of the `using` block.
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlConnection.Open Example/CS/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Data.SqlClient/SqlConnection/Close/source.vb" id="Snippet1":::