-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
813 lines (783 loc) · 27.6 KB
/
index.html
File metadata and controls
813 lines (783 loc) · 27.6 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Sql Server Jam Nuget Package</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Theme Styles -->
<style>
:root {
--bg: #ffffff;
--text: #000000;
--code-bg: #f6f8fa;
--button-bg: #e1e4e8;
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #0d1117;
--text: #c9d1d9;
--code-bg: #161b22;
--button-bg: #30363d;
}
}
body {
background: var(--bg);
color: var(--text);
font-family: system-ui, sans-serif;
max-width: 800px;
margin: auto;
padding: 2rem;
line-height: 1.6;
}
pre {
background: var(--code-bg);
padding: 1em;
overflow-x: auto;
border-radius: 6px;
position: relative;
}
h1, h2, h3 {
border-bottom: 1px solid #ccc;
padding-bottom: 0.3em;
}
a {
color: #1e88e5;
}
/* Copy Button */
.copy-btn {
position: absolute;
top: 0.5em;
right: 0.5em;
background: var(--button-bg);
border: none;
padding: 0.4em;
border-radius: 6px;
cursor: pointer;
font-size: 0.9em;
opacity: 0.7;
display: flex;
align-items: center;
justify-content: center;
}
.copy-btn:hover {
opacity: 1;
}
.copy-btn svg {
width: 1em;
height: 1em;
fill: var(--text);
}
</style>
<!-- Highlight.js GitHub Theme -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css" media="(prefers-color-scheme: dark)">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
<style>
.hljs { background: #f6f8fa }
body { max-width: 1200px }
@media (prefers-color-scheme: dark) {
.hljs { background: #161b22 }
}
</style>
<!-- link rel="stylesheet" href="tables.css" -->
<style>
/* Modern TABLES */
table {
width: 100%;
border-collapse: collapse;
margin: 1.5em 0;
font-size: 0.95em;
border: 1px solid #d0d7de;
}
thead {
background-color: #f6f8fa;
}
@media (prefers-color-scheme: dark) {
thead {
background-color: #161b22;
}
}
th, td {
border: 1px solid #d0d7de;
padding: 0.75em 1em;
text-align: left;
}
th {
font-weight: 600;
}
tr:nth-child(even) {
background-color: rgba(0, 0, 0, 0.03);
}
@media (prefers-color-scheme: dark) {
tr:nth-child(even) {
background-color: rgba(255, 255, 255, 0.05);
}
table, th, td {
border-color: #30363d;
}
}
</style>
<!-- anchors css -->
<style>
.header-anchor {
margin-left: 0.5em;
text-decoration: none;
color: var(--muted-text);
opacity: 0.6;
font-size: 0.8em;
}
.header-anchor:hover {
opacity: 1;
text-decoration: underline;
}
</style>
</head>
<body>
<h2
id="functional-testing-for-.net-applications-with-sql-server-and-localdb">Functional
Testing for .NET Applications with SQL Server and LocalDB</h2>
<p>The intention is to tune SQL Servers for functional tests to achieve
maximum performance, while also providing an accurate description and
connection properties for locally installed SQL Servers and LocalDB
instances.</p>
<p>The entry point is the extension method
<code>Manage(this IDbConnection connection)</code>. The example below
creates new database <strong><em>per test</em></strong> on each local
SQL Server, each LocalDB instance, and an AWS SQL Server propagated via
the <code>SQLSERVER_WELLKNOWN_My_AWS_1</code> environment variable.</p>
<div class="sourceCode" id="cb1"><pre
class="sourceCode csharp"><code class="sourceCode cs"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="op">[</span>Test<span class="op">]</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="op">[</span><span class="fu">TestCaseSource</span><span class="op">(</span><span class="fu">nameof</span><span class="op">(</span>GetEnabledServers<span class="op">))]</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="kw">public</span> <span class="dt">void</span> <span class="fu">Demo1</span><span class="op">(</span>SqlServerRef testCase<span class="op">)</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="op">{</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> IDbConnection cnn <span class="op">=</span> <span class="kw">new</span> <span class="fu">SqlConnection</span><span class="op">(</span>testCase<span class="op">.</span><span class="fu">ConnectionString</span><span class="op">);</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a> cnn<span class="op">.</span><span class="fu">Manage</span><span class="op">().</span><span class="fu">Configuration</span><span class="op">.</span><span class="fu">MinServerMemory</span> <span class="op">=</span> <span class="dv">5000</span><span class="op">;</span> <span class="co">// 5Gb</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a> cnn<span class="op">.</span><span class="fu">Manage</span><span class="op">().</span><span class="fu">Configuration</span><span class="op">.</span><span class="fu">MaxServerMemory</span> <span class="op">=</span> <span class="dv">128000</span><span class="op">;</span> <span class="co">// 128Gb</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a> <span class="dt">string</span> newDbName <span class="op">=</span> $<span class="st">"Test DB {Guid.NewGuid():N}"</span><span class="op">;</span></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a> <span class="kw">try</span></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a> <span class="op">{</span></span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a> cnn<span class="op">.</span><span class="fu">Execute</span><span class="op">(</span>$<span class="st">"Create Database [{newDbName}]"</span><span class="op">);</span></span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true" tabindex="-1"></a> cnn<span class="op">.</span><span class="fu">Manage</span><span class="op">().</span><span class="fu">Databases</span><span class="op">[</span>newDbName<span class="op">].</span><span class="fu">RecoveryMode</span> <span class="op">=</span> DatabaseRecoveryMode<span class="op">.</span><span class="fu">Simple</span><span class="op">;</span></span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true" tabindex="-1"></a> cnn<span class="op">.</span><span class="fu">Manage</span><span class="op">().</span><span class="fu">Databases</span><span class="op">[</span>newDbName<span class="op">].</span><span class="fu">IsAutoShrink</span> <span class="op">=</span> <span class="kw">false</span><span class="op">;</span></span>
<span id="cb1-15"><a href="#cb1-15" aria-hidden="true" tabindex="-1"></a> cnn<span class="op">.</span><span class="fu">Manage</span><span class="op">().</span><span class="fu">Databases</span><span class="op">[</span>newDbName<span class="op">].</span><span class="fu">PageVerify</span> <span class="op">=</span> DatabasePageVerify<span class="op">.</span><span class="fu">None</span><span class="op">;</span></span>
<span id="cb1-16"><a href="#cb1-16" aria-hidden="true" tabindex="-1"></a> cnn<span class="op">.</span><span class="fu">Manage</span><span class="op">().</span><span class="fu">Databases</span><span class="op">[</span>newDbName<span class="op">].</span><span class="fu">AutoCreateStatistic</span> <span class="op">=</span> AutoCreateStatisticMode<span class="op">.</span><span class="fu">Off</span><span class="op">;</span></span>
<span id="cb1-17"><a href="#cb1-17" aria-hidden="true" tabindex="-1"></a> cnn<span class="op">.</span><span class="fu">Manage</span><span class="op">().</span><span class="fu">Databases</span><span class="op">[</span>newDbName<span class="op">].</span><span class="fu">AutoUpdateStatistic</span> <span class="op">=</span> AutoUpdateStatisticMode<span class="op">.</span><span class="fu">Off</span><span class="op">;</span></span>
<span id="cb1-18"><a href="#cb1-18" aria-hidden="true" tabindex="-1"></a> Console<span class="op">.</span><span class="fu">WriteLine</span><span class="op">(</span>$<span class="st">"Success: {cnn.Manage().MediumServerVersion}"</span><span class="op">);</span></span>
<span id="cb1-19"><a href="#cb1-19" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb1-20"><a href="#cb1-20" aria-hidden="true" tabindex="-1"></a> <span class="kw">finally</span></span>
<span id="cb1-21"><a href="#cb1-21" aria-hidden="true" tabindex="-1"></a> <span class="op">{</span></span>
<span id="cb1-22"><a href="#cb1-22" aria-hidden="true" tabindex="-1"></a> ResilientDbKiller<span class="op">.</span><span class="fu">Kill</span><span class="op">(</span>testCase<span class="op">.</span><span class="fu">ConnectionString</span><span class="op">,</span> newDbName<span class="op">);</span></span>
<span id="cb1-23"><a href="#cb1-23" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb1-24"><a href="#cb1-24" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-25"><a href="#cb1-25" aria-hidden="true" tabindex="-1"></a> <span class="co">// Validate newDbName database is deleted</span></span>
<span id="cb1-26"><a href="#cb1-26" aria-hidden="true" tabindex="-1"></a> Assert<span class="op">.</span><span class="fu">That</span><span class="op">(</span>cnn<span class="op">.</span><span class="fu">Manage</span><span class="op">().</span><span class="fu">IsDbExists</span><span class="op">(</span>newDbName<span class="op">),</span> Is<span class="op">.</span><span class="fu">False</span><span class="op">);</span></span>
<span id="cb1-27"><a href="#cb1-27" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span>
<span id="cb1-28"><a href="#cb1-28" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-29"><a href="#cb1-29" aria-hidden="true" tabindex="-1"></a><span class="kw">static</span> IEnumerable<span class="op"><</span>SqlServerRef<span class="op">></span> <span class="fu">GetEnabledServers</span><span class="op">()</span></span>
<span id="cb1-30"><a href="#cb1-30" aria-hidden="true" tabindex="-1"></a><span class="op">{</span></span>
<span id="cb1-31"><a href="#cb1-31" aria-hidden="true" tabindex="-1"></a> <span class="kw">return</span> </span>
<span id="cb1-32"><a href="#cb1-32" aria-hidden="true" tabindex="-1"></a> <span class="co">/* 1 */</span> SqlDiscovery<span class="op">.</span><span class="fu">GetLocalDbAndServerList</span><span class="op">()</span> </span>
<span id="cb1-33"><a href="#cb1-33" aria-hidden="true" tabindex="-1"></a> <span class="co">/* 2 */</span> <span class="op">.</span><span class="fu">Where</span><span class="op">(</span>server <span class="op">=></span> server<span class="op">.</span><span class="fu">ServiceStartup</span> <span class="op">!=</span> LocalServiceStartup<span class="op">.</span><span class="fu">Disabled</span><span class="op">)</span></span>
<span id="cb1-34"><a href="#cb1-34" aria-hidden="true" tabindex="-1"></a> <span class="co">/* 3 */</span> <span class="op">.</span><span class="fu">StartLocalIfStopped</span><span class="op">()</span></span>
<span id="cb1-35"><a href="#cb1-35" aria-hidden="true" tabindex="-1"></a> <span class="co">/* 4 */</span> <span class="op">.</span><span class="fu">WarmUp</span><span class="op">(</span>timeout<span class="op">:</span> TimeSpan<span class="op">.</span><span class="fu">FromSeconds</span><span class="op">(</span><span class="dv">30</span><span class="op">))</span></span>
<span id="cb1-36"><a href="#cb1-36" aria-hidden="true" tabindex="-1"></a> <span class="co">/* 5 */</span> <span class="op">.</span><span class="fu">Where</span><span class="op">(</span>server <span class="op">=></span> server<span class="op">.</span><span class="fu">Version</span> <span class="op">!=</span> <span class="kw">null</span><span class="op">)</span></span>
<span id="cb1-37"><a href="#cb1-37" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">Where</span><span class="op">(</span>server <span class="op">=></span> server<span class="op">.</span><span class="fu">Manage</span><span class="op">().</span><span class="fu">EngineEdition</span> <span class="op">==</span> EngineEdition<span class="op">.</span><span class="fu">Enterprise</span><span class="op">)</span> <span class="co">// Developer|Enterprise</span></span>
<span id="cb1-38"><a href="#cb1-38" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">Where</span><span class="op">(</span>server <span class="op">=></span> server<span class="op">.</span><span class="fu">Manage</span><span class="op">().</span><span class="fu">ShortServerVersion</span><span class="op">.</span><span class="fu">Major</span> <span class="op">>=</span> <span class="dv">15</span><span class="op">)</span> <span class="co">// 2019 or above</span></span>
<span id="cb1-39"><a href="#cb1-39" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">OrderByVersionDesc</span><span class="op">()</span></span>
<span id="cb1-40"><a href="#cb1-40" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">ToList</span><span class="op">();</span></span>
<span id="cb1-41"><a href="#cb1-41" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
<ul>
<li>Line ①: Retrieves all locally pre-installed SQL Servers
(<code>Kind=Local</code>) and all pre-installed LocalDB instances
(<code>Kind=LocalDB</code>). At this step, the <code>DataSource</code>
and <code>InstallerVersion</code> properties are populated. No
communication with SQL Server is performed during this step.
Additionally, for local SQL Server instances, the
<code>ServiceStartup</code> property is also populated.</li>
<li>Line ②: Filters out disabled SQL Server windows services.</li>
<li>Line ③: Starts local SQL Servers and LocalDB instances if they are
not already running. On Linux and macOS it has no effect.</li>
<li>Line ④: Waits up to 30 seconds for each SQL Server health check to
complete and populates the <code>Version</code> property.</li>
<li>Line ⑤: Filter out non-healthy SQL Server instances from the
previous step. This filter and two next are a dubious ones in most
cases, but it is added for illustration purposes. Apparently, a
non-responsive SQL Server should be fixed/removed if you control your
development environment and your CI pipeline.</li>
</ul>
<h2 id="sql-server-management-extensions">SQL Server Management
Extensions</h2>
<table>
<colgroup>
<col style="width: 28%" />
<col style="width: 20%" />
<col style="width: 25%" />
<col style="width: 25%" />
</colgroup>
<thead>
<tr>
<th>Data Type</th>
<th>Member</th>
<th>Readonly</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<tr>
<td>Version</td>
<td>ShortServerVersion</td>
<td>read-only</td>
<td>@<span class="citation"
data-cites="MICROSOFTVERSION">@MICROSOFTVERSION</span></td>
</tr>
<tr>
<td>bool</td>
<td>IsLocalDB</td>
<td>read-only</td>
<td></td>
</tr>
<tr>
<td>bool</td>
<td>IsAzure</td>
<td>read-only</td>
<td></td>
</tr>
<tr>
<td>bool</td>
<td>IsExpressOrLocalDb</td>
<td>read-only</td>
<td></td>
</tr>
<tr>
<td>EngineEdition</td>
<td>EngineEdition</td>
<td>read-only</td>
<td>Standard, Exterprise, Express, SqlDatabase, SqlDataWarehouse,
Personal</td>
</tr>
<tr>
<td>string</td>
<td>EngineEditionName</td>
<td>read-only</td>
<td>“SQL Azure”, “Express Edition”, “Developer Edition”, “Enterprise
Edition”, …</td>
</tr>
<tr>
<td>string</td>
<td>LongServerVersion</td>
<td>read-only</td>
<td>@<span class="citation" data-cites="VERSION">@VERSION</span></td>
</tr>
<tr>
<td>string</td>
<td>MediumServerVersion</td>
<td>read-only</td>
<td></td>
</tr>
<tr>
<td>SecurityMode</td>
<td>SecurityMode</td>
<td>read-only</td>
<td>IntegratedOnly, Both</td>
</tr>
<tr>
<td>string</td>
<td>ProductVersion</td>
<td>read-only</td>
<td>GetServerProperty<string>(“ProductVersion”)</td>
</tr>
<tr>
<td>string</td>
<td>ProductLevel</td>
<td>read-only</td>
<td>CTP, RTM, SP1, SP2, …</td>
</tr>
<tr>
<td>string</td>
<td>ProductUpdateLevel</td>
<td>read-only</td>
<td>CU1, CU2, …</td>
</tr>
<tr>
<td>string</td>
<td>CpuName</td>
<td>read-only</td>
<td>Accurate name on Windows only</td>
</tr>
<tr>
<td>int</td>
<td>CpuCount</td>
<td>read-only</td>
<td></td>
</tr>
<tr>
<td>bool</td>
<td>IsCpuAffinitySupported</td>
<td>read-only</td>
<td>If not an express edition</td>
</tr>
<tr>
<td>long</td>
<td>AvailableMemoryKb</td>
<td>read-only</td>
<td>process_memory_limit_mb, Committed_Target_Kb, or Visible_Target_Kb
depending on edition and version</td>
</tr>
<tr>
<td>long</td>
<td>CommittedMemoryKb</td>
<td>read-only</td>
<td>Committed_Kb</td>
</tr>
<tr>
<td>long</td>
<td>PhysicalMemoryKb</td>
<td>read-only</td>
<td>physical_memory_in_bytes or physical_memory_kb depending on
version</td>
</tr>
<tr>
<td>string</td>
<td>ServerCollation</td>
<td>read-only</td>
<td>GetServerProperty<string>(“Collation”)</td>
</tr>
<tr>
<td>bool</td>
<td>IsFullTextSearchInstalled</td>
<td>read-only</td>
<td></td>
</tr>
<tr>
<td>bool</td>
<td>IsFileStreamSupported</td>
<td>read-only</td>
<td>this.ShortServerVersion.Major >= 10 &&
!this.IsLocalDB</td>
</tr>
<tr>
<td>string</td>
<td>HostPlatform</td>
<td>read-only</td>
<td>“Windows” or “Linux”</td>
</tr>
<tr>
<td>bool</td>
<td>IsWindows</td>
<td>read-only</td>
<td></td>
</tr>
<tr>
<td>bool</td>
<td>IsLinux</td>
<td>read-only</td>
<td></td>
</tr>
<tr>
<td>SqlDefaultPaths</td>
<td>DefaultPaths</td>
<td>read-only</td>
<td>Data, Log, and Backup folders</td>
</tr>
<tr>
<td>FixedServerRoles</td>
<td>FixedServerRoles</td>
<td>read-only</td>
<td>SysAdmin, SetupAdmin, ServerAdmin, SecurityAdmin, ProcessAdmin,
…</td>
</tr>
<tr>
<td>bool</td>
<td>IsCompressedBackupSupported</td>
<td>read-only</td>
<td>this.EngineEdition == EngineEdition.Enterprise &&
this.ShortServerVersion.Major >= 10</td>
</tr>
<tr>
<td>bool</td>
<td>IsMemoryOptimizedTableSupported</td>
<td>read-only</td>
<td>Depends on edition, version and update level</td>
</tr>
<tr>
<td>bool</td>
<td>IsConnectionEncrypted</td>
<td>read-only</td>
<td></td>
</tr>
<tr>
<td>string</td>
<td>NetTransport</td>
<td>read-only</td>
<td>“TCP”, “Shared Memory”, “Named Pipe”</td>
</tr>
<tr>
<td>int</td>
<td>CurrentSPID</td>
<td>read-only</td>
<td>@<span class="citation" data-cites="SPID">@SPID</span>, has no sense
if IDbConnection is closed</td>
</tr>
<tr>
<td>string</td>
<td>CurrentDatabaseName</td>
<td>read-only</td>
<td>DB_NAME()</td>
</tr>
<tr>
<td>DatabaseOptionsManagement</td>
<td>CurrentDatabase</td>
<td>read-only</td>
<td>this.Databases[this.CurrentDatabaseName]</td>
</tr>
<tr>
<td>DatabaseOptionsManagement</td>
<td>Databases[“Db1”]</td>
<td>read-only</td>
<td></td>
</tr>
<tr>
<td>HashSet<string></td>
<td>FindCollations(params string[] namesOrPatters)</td>
<td></td>
<td></td>
</tr>
<tr>
<td>SqlBackupDescription</td>
<td>GetBackupDescription (string bakFullPath)</td>
<td></td>
<td>Backups and files inside each backup</td>
</tr>
<tr>
<td>bool</td>
<td>IsDbExists(string dbName)</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<h2 id="sql-server-configuration">SQL Server Configuration</h2>
<p>The entry point is the extension method
<code>Manage(this IDbConnection connection).Configuration</code></p>
<table>
<colgroup>
<col style="width: 28%" />
<col style="width: 20%" />
<col style="width: 25%" />
<col style="width: 25%" />
</colgroup>
<thead>
<tr>
<th>Data Type</th>
<th>Member</th>
<th>Readonly</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<tr>
<td>short</td>
<td>AffinityCount</td>
<td>read/write</td>
<td>Cores Count, 1 … Cpu Count</td>
</tr>
<tr>
<td>long</td>
<td>AffinityMask</td>
<td>read/write</td>
<td>sp_configure ‘affinity[64] mask’</td>
</tr>
<tr>
<td>bool</td>
<td>ClrEnabled</td>
<td>read/write</td>
<td>sp_configure ‘clr enabled’</td>
</tr>
<tr>
<td>bool</td>
<td>ServerTriggerRecursion</td>
<td>read/write</td>
<td>sp_configure ‘server trigger recursion’</td>
</tr>
<tr>
<td>bool</td>
<td>ShowAdvancedOption</td>
<td>read/write</td>
<td>sp_configure ‘show advanced option’</td>
</tr>
<tr>
<td>FileStreamAccessLevels</td>
<td>FileStreamAccessLevel</td>
<td>read/write</td>
<td>sp_configure ‘filestream access level’</td>
</tr>
<tr>
<td>bool</td>
<td>BackupCompressionDefault</td>
<td>read/write</td>
<td>sp_configure ‘backup compression default’</td>
</tr>
<tr>
<td>bool</td>
<td>XpCmdShell</td>
<td>read/write</td>
<td>sp_configure ‘xp_cmdshell’</td>
</tr>
<tr>
<td>int</td>
<td>MaxServerMemory</td>
<td>read/write</td>
<td>sp_configure ‘max server memory (MB)’</td>
</tr>
<tr>
<td>int</td>
<td>MinServerMemory</td>
<td>read/write</td>
<td>sp_configure ‘min server memory (MB)’</td>
</tr>
</tbody>
</table>
<p>Generic SQL Server configuration API:</p>
<ul>
<li><code>Option<T> ReadAdvancedOption<T>(string<T> name)</code></li>
<li><code>void SetAdvancedOption<T>(string name, T value)</code></li>
<li><code>Option<T> ReadOption<T>(string name)</code></li>
<li><code>void SetOption<T>(string name, T value)</code></li>
</ul>
<h2 id="sql-database-management-extensions">SQL Database Management
Extensions</h2>
<table>
<colgroup>
<col style="width: 28%" />
<col style="width: 20%" />
<col style="width: 25%" />
<col style="width: 25%" />
</colgroup>
<thead>
<tr>
<th>Data Type</th>
<th>Member</th>
<th>Readonly</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<tr>
<td>bool</td>
<td>Exists</td>
<td>readonly</td>
<td></td>
</tr>
<tr>
<td>void</td>
<td>SetState(TargetDatabaseState newState)</td>
<td></td>
<td>Online, Offline, Emergency</td>
</tr>
<tr>
<td>void</td>
<td>Shrink(ShrinkOptions options, int? commandTimeout)</td>
<td></td>
<td>options are: Shink and Truncate, Shrink only, Truncate only</td>
</tr>
<tr>
<td>bool</td>
<td>IsReadOnly</td>
<td>read/write</td>
<td></td>
</tr>
<tr>
<td>DatabaseRecoveryMode</td>
<td>RecoveryMode</td>
<td>read/write</td>
<td>Simple, Bulk logged, or Full</td>
</tr>
<tr>
<td>DatabasePageVerify</td>
<td>PageVerify</td>
<td>read/write</td>
<td>Checksum, Torn Page Detection, or None. Not supported by Azure</td>
</tr>
<tr>
<td>bool</td>
<td>IsAutoShrink</td>
<td>read/write</td>
<td></td>
</tr>
<tr>
<td>bool</td>
<td>AreTriggersRecursive</td>
<td>read/write</td>
<td></td>
</tr>
<tr>
<td>bool</td>
<td>IsIncrementalAutoStatisticCreationSupported</td>
<td>read-only</td>
<td>ServerVersion.Major >= 12</td>
</tr>
<tr>
<td>AutoCreateStatisticMode</td>
<td>AutoCreateStatistic</td>
<td>read/write</td>
<td>Complete, Incremental, Off</td>
</tr>
<tr>
<td>AutoUpdateStatisticMode</td>
<td>AutoUpdateStatistic</td>
<td>read/write</td>
<td>Synchronously, Async, Off</td>
</tr>
<tr>
<td>bool</td>
<td>IsBrokerEnabled</td>
<td>read/write</td>
<td></td>
</tr>
<tr>
<td>string</td>
<td>DefaultCollationName</td>
<td>read/write</td>
<td></td>
</tr>
<tr>
<td>string</td>
<td>StateDescription</td>
<td>read-only</td>
<td>Online, Offline, Emergency, Restoring, Recovering…</td>
</tr>
<tr>
<td>bool</td>
<td>IsOnline</td>
<td>read-only</td>
<td></td>
</tr>
<tr>
<td>DatabaseComparisonStyle</td>
<td>ComparisonStyle</td>
<td>read-only</td>
<td>flags IgnoreCase, IgnoreAccent, IgnoreKana, IgnoreWidth</td>
</tr>
<tr>
<td>bool</td>
<td>IsClone</td>
<td>read-only</td>
<td></td>
</tr>
<tr>
<td>string</td>
<td>AzureServiceObjective</td>
<td>read-only</td>
<td>S0, S1, S2, ElasticPool…</td>
</tr>
<tr>
<td>string</td>
<td>AzureEdition</td>
<td>read-only</td>
<td>Basic, Standard, Premium…</td>
</tr>
<tr>
<td>string</td>
<td>AzureElasticPool</td>
<td>read-only</td>
<td>sys.database_service_objectives.elastic_pool_name</td>
</tr>
<tr>
<td>long</td>
<td>Size</td>
<td>read-only</td>
<td></td>
</tr>
<tr>
<td>bool</td>
<td>IsFullTextEnabled</td>
<td>read-only</td>
<td></td>
</tr>
<tr>
<td>string</td>
<td>OwnerName</td>
<td>read-only</td>
<td></td>
</tr>
<tr>
<td>bool</td>
<td>HasMemoryOptimizedTableFileGroup</td>
<td>read-only</td>
<td></td>
</tr>
</tbody>
</table>
<h2 id="sql-server-discovery">SQL Server Discovery</h2>
<p>On <strong>Windows</strong>, SQL Server instances and their versions
are discovered via the registry path
<code>HKLM\Software\Microsoft\Microsoft SQL Server</code> (<a
href="https://learn.microsoft.com/en-us/sql/sql-server/install/file-locations-for-default-and-named-instances-of-sql-server">reference</a>).</p>
<p>On <strong>Linux</strong> and <strong>macOS</strong>, SQL Server
instance information is provided through environment variables prefixed
with <code>SQLSERVER_WELLKNOWN_***</code>.</p>
<!-- Add copy buttons -->
<script>
var copyIcon;
copyIcon = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M10 1.75a.75.75 0 0 1 .75.75v.75h1.5A2.75 2.75 0 0 1 15 6v6.25A2.75 2.75 0 0 1 12.25 15H6a.75.75 0 0 1 0-1.5h6.25c.69 0 1.25-.56 1.25-1.25V6c0-.69-.56-1.25-1.25-1.25h-1.5v.75a.75.75 0 0 1-1.5 0V2.5a.75.75 0 0 1 .75-.75ZM2.75 3A2.75 2.75 0 0 0 0 5.75v6.5A2.75 2.75 0 0 0 2.75 15h6.5A2.75 2.75 0 0 0 12 12.25v-6.5A2.75 2.75 0 0 0 9.25 3h-6.5Zm0 1.5h6.5c.69 0 1.25.56 1.25 1.25v6.5c0 .69-.56 1.25-1.25 1.25h-6.5C2.06 13.5 1.5 12.94 1.5 12.25v-6.5C1.5 5.06 2.06 4.5 2.75 4.5Z"/></svg>
`;
copyIcon = `
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24">
<path d="M16 1H4a2 2 0 0 0-2 2v12h2V3h12V1Zm3 4H8a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h11a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2Zm0 16H8V7h11v14Z"/>
</svg>`;
var checkIcon = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M13.78 3.72a.75.75 0 0 1 0 1.06l-7.25 7.25a.75.75 0 0 1-1.06 0L2.22 8.78a.75.75 0 1 1 1.06-1.06l2.72 2.72 6.72-6.72a.75.75 0 0 1 1.06 0Z"/></svg>
`;
checkIcon = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor">
<path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 0 0-1.06 0L6.5 10.44 3.28 7.22a.75.75 0 1 0-1.06 1.06l3.75 3.75a.75.75 0 0 0 1.06 0l6.75-6.75a.75.75 0 0 0 0-1.06z"/>
</svg>
`;
document.querySelectorAll('pre code').forEach((block) => {
const button = document.createElement('button');
button.className = 'copy-btn';
button.innerHTML = copyIcon;
button.addEventListener('click', () => {
navigator.clipboard.writeText(block.innerText).then(() => {
button.innerHTML = checkIcon;
setTimeout(() => button.innerHTML = copyIcon, 1500);
});
});
block.parentNode.appendChild(button);
});
</script>
<!-- anchors js -->
<script>
function slugify(text) {
return text.toLowerCase()
.trim()
.replace(/[^a-z0-9\s-]/g, '') // Remove special chars
.replace(/\s+/g, '-') // Replace spaces with dashes
.replace(/-+/g, '-'); // Collapse multiple dashes
}
document.querySelectorAll('h1, h2, h3, h4, h5, h6').forEach(header => {
var slug = slugify(header.textContent);
header.id = slug;
const anchor = document.createElement('a');
anchor.href = '#' + slug;
anchor.className = 'header-anchor';
anchor.setAttribute('aria-label', 'Permalink: ' + header.textContent);
anchor.textContent = '#';
/*
anchor.addEventListener('click', e => {
e.preventDefault();
if (location.hash === `#`) {
history.replaceState(null, null, `#`);
} else {
location.hash = slug;
}
});
*/
header.appendChild(anchor);
});
</script>
</body>
</html>