[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mcs / class / System.Data / Test / System.Data.SqlClient / SqlConnectionTest.cs
blob459b86dc0bdb4cd56ea046a8bfcf41069c3b6caa
1 //
2 // SqlConnectionTest.cs - NUnit Test Cases for testing the
3 // SqlConnection class
4 // Author:
5 // Gert Driesen (drieseng@users.sourceforge.net)
6 //
7 // Copyright (c) 2004 Novell Inc., and the individuals listed
8 // on the ChangeLog entries.
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System;
31 using System.Data;
32 using System.Data.SqlClient;
34 using NUnit.Framework;
36 namespace MonoTests.System.Data.SqlClient
38 [TestFixture]
39 public class SqlConnectionTest
41 [Test] // SqlConnection ()
42 #if FEATURE_NO_BSD_SOCKETS
43 [ExpectedException (typeof (PlatformNotSupportedException))]
44 #endif
45 public void Constructor1 ()
47 SqlConnection cn = new SqlConnection ();
49 Assert.AreEqual (string.Empty, cn.ConnectionString, "#1");
50 Assert.AreEqual (15, cn.ConnectionTimeout, "#2");
51 Assert.IsNull (cn.Container, "#3");
52 Assert.AreEqual (string.Empty, cn.Database, "#4");
53 Assert.AreEqual (string.Empty, cn.DataSource, "#5");
54 Assert.IsFalse (cn.FireInfoMessageEventOnUserErrors, "#6");
55 Assert.AreEqual (8000, cn.PacketSize, "#7");
56 Assert.IsNull (cn.Site, "#8");
57 Assert.AreEqual (ConnectionState.Closed, cn.State, "#9");
58 Assert.IsFalse (cn.StatisticsEnabled, "#10");
59 // https://github.com/dotnet/corefx/issues/22871
60 //Assert.IsTrue (string.Compare (Environment.MachineName, cn.WorkstationId, true) == 0, "#11");
63 [Test] // SqlConnection (string)
64 #if FEATURE_NO_BSD_SOCKETS
65 [ExpectedException (typeof (PlatformNotSupportedException))]
66 #endif
67 public void Constructor2 ()
69 string connectionString = "server=SQLSRV; database=Mono;";
71 SqlConnection cn = new SqlConnection (connectionString);
72 Assert.AreEqual (connectionString, cn.ConnectionString, "#A1");
73 Assert.AreEqual (15, cn.ConnectionTimeout, "#A2");
74 Assert.IsNull (cn.Container, "#A3");
75 Assert.AreEqual ("Mono", cn.Database, "#A4");
76 Assert.AreEqual ("SQLSRV", cn.DataSource, "#A5");
77 Assert.IsFalse (cn.FireInfoMessageEventOnUserErrors, "#A6");
78 Assert.AreEqual (8000, cn.PacketSize, "#A7");
79 Assert.IsNull (cn.Site, "#A8");
80 Assert.AreEqual (ConnectionState.Closed, cn.State, "#A9");
81 Assert.IsFalse (cn.StatisticsEnabled, "#A10");
82 // https://github.com/dotnet/corefx/issues/22871
83 //Assert.IsTrue (string.Compare (Environment.MachineName, cn.WorkstationId, true) == 0, "#A11");
85 cn = new SqlConnection ((string) null);
86 Assert.AreEqual (string.Empty, cn.ConnectionString, "#B1");
87 Assert.AreEqual (15, cn.ConnectionTimeout, "#B2");
88 Assert.IsNull (cn.Container, "#B3");
89 Assert.AreEqual (string.Empty, cn.Database, "#B4");
90 Assert.AreEqual (string.Empty, cn.DataSource, "#B5");
91 Assert.IsFalse (cn.FireInfoMessageEventOnUserErrors, "#B6");
92 Assert.AreEqual (8000, cn.PacketSize, "#B7");
93 Assert.IsNull (cn.Site, "#B8");
94 Assert.AreEqual (ConnectionState.Closed, cn.State, "#B9");
95 Assert.IsFalse (cn.StatisticsEnabled, "#B10");
96 // https://github.com/dotnet/corefx/issues/22871
97 //Assert.IsTrue (string.Compare (Environment.MachineName, cn.WorkstationId, true) == 0, "#B11");
100 [Test]
101 #if FEATURE_NO_BSD_SOCKETS
102 [ExpectedException (typeof (PlatformNotSupportedException))]
103 #endif
104 public void Constructor2_ConnectionString_Invalid ()
106 try {
107 new SqlConnection ("InvalidConnectionString");
108 Assert.Fail ("#A1");
109 } catch (ArgumentException ex) {
110 // Format of the initialization string does
111 // not conform to specification starting at
112 // index 0
113 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
114 Assert.IsNull (ex.InnerException, "#A3");
115 Assert.IsNotNull (ex.Message, "#A4");
116 Assert.IsNull (ex.ParamName, "#A5");
119 // invalid keyword
120 try {
121 new SqlConnection ("invalidKeyword=10");
122 Assert.Fail ("#B1");
123 } catch (ArgumentException ex) {
124 // Keyword not supported: 'invalidkeyword'
125 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
126 Assert.IsNull (ex.InnerException, "#B3");
127 Assert.IsNotNull (ex.Message, "#B4");
128 Assert.IsTrue (ex.Message.IndexOf ("'invalidkeyword'") != -1, "#B5");
129 Assert.IsNull (ex.ParamName, "#B6");
132 // invalid packet size (< minimum)
133 try {
134 new SqlConnection ("Packet Size=511");
135 Assert.Fail ("#C1");
136 } catch (ArgumentException ex) {
137 // Invalid 'Packet Size'. The value must be an
138 // integer >= 512 and <= 32768
139 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
140 Assert.IsNull (ex.InnerException, "#C3");
141 Assert.IsNotNull (ex.Message, "#C4");
142 Assert.IsNull (ex.ParamName, "#C5");
145 // invalid packet size (> maximum)
146 try {
147 new SqlConnection ("Packet Size=32769");
148 Assert.Fail ("#D1");
149 } catch (ArgumentException ex) {
150 // Invalid 'Packet Size'. The value must be an
151 // integer >= 512 and <= 32768
152 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
153 Assert.IsNull (ex.InnerException, "#D3");
154 Assert.IsNotNull (ex.Message, "#D4");
155 Assert.IsNull (ex.ParamName, "#D5");
158 // negative connect timeout
159 try {
160 new SqlConnection ("Connect Timeout=-1");
161 Assert.Fail ("#E1");
162 } catch (ArgumentException ex) {
163 // Invalid value for key 'connect timeout'
164 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#E2");
165 Assert.IsNull (ex.InnerException, "#E3");
166 Assert.IsNotNull (ex.Message, "#E4");
167 Assert.IsNull (ex.ParamName, "#E5");
170 // negative max pool size
171 try {
172 new SqlConnection ("Max Pool Size=-1");
173 Assert.Fail ("#F1");
174 } catch (ArgumentException ex) {
175 // Invalid value for key 'max pool size'
176 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#F2");
177 Assert.IsNull (ex.InnerException, "#F3");
178 Assert.IsNotNull (ex.Message, "#F4");
179 Assert.IsNull (ex.ParamName, "#F5");
182 // negative min pool size
183 try {
184 new SqlConnection ("Min Pool Size=-1");
185 Assert.Fail ("#G1");
186 } catch (ArgumentException ex) {
187 // Invalid value for key 'min pool size'
188 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#G2");
189 Assert.IsNull (ex.InnerException, "#G3");
190 Assert.IsNotNull (ex.Message, "#G4");
191 Assert.IsNull (ex.ParamName, "#G5");
195 [Test]
196 #if FEATURE_NO_BSD_SOCKETS
197 [ExpectedException (typeof (PlatformNotSupportedException))]
198 #endif
199 public void BeginTransaction_Connection_Closed ()
201 SqlConnection cn = new SqlConnection ();
203 try {
204 cn.BeginTransaction ();
205 Assert.Fail ("#A1");
206 } catch (InvalidOperationException ex) {
207 // Invalid operation. The connection is closed
208 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
209 Assert.IsNull (ex.InnerException, "#A3");
210 Assert.IsNotNull (ex.Message, "#A4");
213 try {
214 cn.BeginTransaction ((IsolationLevel) 666);
215 Assert.Fail ("#B1");
216 } catch (InvalidOperationException ex) {
217 // Invalid operation. The connection is closed
218 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
219 Assert.IsNull (ex.InnerException, "#B3");
220 Assert.IsNotNull (ex.Message, "#B4");
223 try {
224 cn.BeginTransaction (IsolationLevel.Serializable);
225 Assert.Fail ("#C1");
226 } catch (InvalidOperationException ex) {
227 // Invalid operation. The connection is closed
228 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
229 Assert.IsNull (ex.InnerException, "#C3");
230 Assert.IsNotNull (ex.Message, "#C4");
233 try {
234 cn.BeginTransaction ("trans");
235 Assert.Fail ("#D1");
236 } catch (InvalidOperationException ex) {
237 // Invalid operation. The connection is closed
238 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
239 Assert.IsNull (ex.InnerException, "#D3");
240 Assert.IsNotNull (ex.Message, "#D4");
243 try {
244 cn.BeginTransaction ((IsolationLevel) 666, "trans");
245 Assert.Fail ("#E1");
246 } catch (InvalidOperationException ex) {
247 // Invalid operation. The connection is closed
248 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E2");
249 Assert.IsNull (ex.InnerException, "#E3");
250 Assert.IsNotNull (ex.Message, "#E4");
253 try {
254 cn.BeginTransaction (IsolationLevel.Serializable, "trans");
255 Assert.Fail ("#F1");
256 } catch (InvalidOperationException ex) {
257 // Invalid operation. The connection is closed
258 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#F2");
259 Assert.IsNull (ex.InnerException, "#F3");
260 Assert.IsNotNull (ex.Message, "#F4");
264 [Test]
265 #if FEATURE_NO_BSD_SOCKETS
266 [ExpectedException (typeof (PlatformNotSupportedException))]
267 #endif
268 public void ChangeDatabase_Connection_Closed ()
270 SqlConnection cn = new SqlConnection ();
271 cn.ConnectionString = "server=SQLSRV";
273 try {
274 cn.ChangeDatabase ("database");
275 Assert.Fail ("#1");
276 } catch (InvalidOperationException ex) {
277 // Invalid operation. The connection is closed
278 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
279 Assert.IsNull (ex.InnerException, "#3");
280 Assert.IsNotNull (ex.Message, "#4");
284 [Test]
285 [Category("NotWorking")] // https://github.com/dotnet/corefx/issues/11958
286 #if FEATURE_NO_BSD_SOCKETS
287 [ExpectedException (typeof (PlatformNotSupportedException))]
288 #endif
289 public void ChangePassword_ConnectionString_Empty ()
291 try {
292 SqlConnection.ChangePassword (string.Empty, "mono");
293 Assert.Fail ("#1");
294 } catch (ArgumentNullException ex) {
295 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
296 Assert.IsNull (ex.InnerException, "#3");
297 Assert.IsNotNull (ex.Message, "#4");
298 Assert.IsNotNull (ex.ParamName, "#5");
299 Assert.IsTrue (ex.ParamName.IndexOf ("'connectionString'") != -1, "#6");
303 [Test]
304 [Category("NotWorking")] // https://github.com/dotnet/corefx/issues/11958
305 #if FEATURE_NO_BSD_SOCKETS
306 [ExpectedException (typeof (PlatformNotSupportedException))]
307 #endif
308 public void ChangePassword_ConnectionString_Null ()
310 try {
311 SqlConnection.ChangePassword ((string) null, "mono");
312 Assert.Fail ("#1");
313 } catch (ArgumentNullException ex) {
314 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
315 Assert.IsNull (ex.InnerException, "#3");
316 Assert.IsNotNull (ex.Message, "#4");
317 Assert.IsNotNull (ex.ParamName, "#5");
318 Assert.IsTrue (ex.ParamName.IndexOf ("'connectionString'") != -1, "#6");
323 #if FEATURE_NO_BSD_SOCKETS
324 [ExpectedException (typeof (PlatformNotSupportedException))]
325 #endif
326 public void ChangePassword_NewPassword_Empty ()
328 try {
329 SqlConnection.ChangePassword ("server=SQLSRV", string.Empty);
330 Assert.Fail ("#1");
331 } catch (ArgumentNullException ex) {
332 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
333 Assert.IsNull (ex.InnerException, "#3");
334 Assert.IsNotNull (ex.Message, "#4");
335 Assert.IsNotNull (ex.ParamName, "#5");
336 Assert.IsTrue (ex.ParamName.IndexOf ("'newPassword'") != -1, "#6");
340 [Test]
341 [Category("NotWorking")] // https://github.com/dotnet/corefx/issues/11958
342 #if FEATURE_NO_BSD_SOCKETS
343 [ExpectedException (typeof (PlatformNotSupportedException))]
344 #endif
345 public void ChangePassword_NewPassword_ExceedMaxLength ()
347 try {
348 SqlConnection.ChangePassword ("server=SQLSRV",
349 new string ('d', 129));
350 Assert.Fail ("#1");
351 } catch (ArgumentException ex) {
352 // The length of argument 'newPassword' exceeds
353 // it's limit of '128'
354 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
355 Assert.IsNull (ex.InnerException, "#3");
356 Assert.IsNotNull (ex.Message, "#4");
357 Assert.IsTrue (ex.Message.IndexOf ("'newPassword'") != -1, "#5");
358 Assert.IsTrue (ex.Message.IndexOf ("128") != -1, "#6");
359 Assert.IsNull (ex.ParamName, "#7");
363 [Test]
364 [Category("NotWorking")] // https://github.com/dotnet/corefx/issues/11958
365 #if FEATURE_NO_BSD_SOCKETS
366 [ExpectedException (typeof (PlatformNotSupportedException))]
367 #endif
368 public void ChangePassword_NewPassword_Null ()
370 try {
371 SqlConnection.ChangePassword ("server=SQLSRV", (string) null);
372 Assert.Fail ("#1");
373 } catch (ArgumentNullException ex) {
374 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
375 Assert.IsNull (ex.InnerException, "#3");
376 Assert.IsNotNull (ex.Message, "#4");
377 Assert.IsNotNull (ex.ParamName, "#5");
378 Assert.IsTrue (ex.ParamName.IndexOf ("'newPassword'") != -1, "#6");
382 [Test]
383 #if FEATURE_NO_BSD_SOCKETS
384 [ExpectedException (typeof (PlatformNotSupportedException))]
385 #endif
386 public void ClearPool_Connection_Null ()
388 try {
389 SqlConnection.ClearPool ((SqlConnection) null);
390 Assert.Fail ("#1");
391 } catch (ArgumentNullException ex) {
392 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
393 Assert.IsNull (ex.InnerException, "#3");
394 Assert.IsNotNull (ex.Message, "#4");
395 Assert.AreEqual ("connection", ex.ParamName, "#5");
399 [Test]
400 #if FEATURE_NO_BSD_SOCKETS
401 [ExpectedException (typeof (PlatformNotSupportedException))]
402 #endif
403 public void ConnectionString ()
405 SqlConnection cn = new SqlConnection ();
406 cn.ConnectionString = "server=SQLSRV";
407 Assert.AreEqual ("server=SQLSRV", cn.ConnectionString, "#1");
408 cn.ConnectionString = null;
409 Assert.AreEqual (string.Empty, cn.ConnectionString, "#2");
410 cn.ConnectionString = "server=SQLSRV";
411 Assert.AreEqual ("server=SQLSRV", cn.ConnectionString, "#3");
412 cn.ConnectionString = string.Empty;
413 Assert.AreEqual (string.Empty, cn.ConnectionString, "#4");
416 [Test]
417 #if FEATURE_NO_BSD_SOCKETS
418 [ExpectedException (typeof (PlatformNotSupportedException))]
419 #endif
420 public void ConnectionString_Value_Invalid ()
422 SqlConnection cn = new SqlConnection ();
424 try {
425 cn.ConnectionString = "InvalidConnectionString";
426 Assert.Fail ("#A1");
427 } catch (ArgumentException ex) {
428 // Format of the initialization string does
429 // not conform to specification starting at
430 // index 0
431 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
432 Assert.IsNull (ex.InnerException, "#A3");
433 Assert.IsNotNull (ex.Message, "#A4");
434 Assert.IsNull (ex.ParamName, "#A5");
437 // invalid keyword
438 try {
439 cn.ConnectionString = "invalidKeyword=10";
440 Assert.Fail ("#B1");
441 } catch (ArgumentException ex) {
442 // Keyword not supported: 'invalidkeyword'
443 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
444 Assert.IsNull (ex.InnerException, "#B3");
445 Assert.IsNotNull (ex.Message, "#B4");
446 Assert.IsTrue (ex.Message.IndexOf ("'invalidkeyword'") != -1, "#B5");
447 Assert.IsNull (ex.ParamName, "#B6");
451 [Test]
452 #if FEATURE_NO_BSD_SOCKETS
453 [ExpectedException (typeof (PlatformNotSupportedException))]
454 #endif
455 public void CreateCommand ()
457 SqlConnection cn = new SqlConnection ();
458 SqlCommand cmd = cn.CreateCommand ();
459 Assert.IsNotNull (cmd, "#1");
460 Assert.AreEqual (string.Empty, cmd.CommandText, "#2");
461 Assert.AreEqual (30, cmd.CommandTimeout, "#3");
462 Assert.AreEqual (CommandType.Text, cmd.CommandType, "#4");
463 Assert.AreSame (cn, cmd.Connection, "#5");
464 Assert.IsNull (cmd.Container, "#6");
465 Assert.IsTrue (cmd.DesignTimeVisible, "#7");
466 Assert.IsNull (cmd.Notification, "#8");
467 // not implemented in corefx yet
468 // Assert.IsTrue (cmd.NotificationAutoEnlist, "#9");
469 Assert.IsNotNull (cmd.Parameters, "#10");
470 Assert.AreEqual (0, cmd.Parameters.Count, "#11");
471 Assert.IsNull (cmd.Site, "#12");
472 Assert.IsNull (cmd.Transaction, "#13");
473 Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#14");
476 [Test]
477 #if FEATURE_NO_BSD_SOCKETS
478 [ExpectedException (typeof (PlatformNotSupportedException))]
479 #endif
480 public void Dispose ()
482 SqlConnection cn = new SqlConnection ("Server=SQLSRV;Database=master;Timeout=25;Packet Size=512;Workstation ID=DUMMY");
483 cn.Dispose ();
485 Assert.AreEqual (string.Empty, cn.ConnectionString, "#1");
486 Assert.AreEqual (15, cn.ConnectionTimeout, "#2");
487 Assert.AreEqual (string.Empty, cn.Database, "#3");
488 Assert.AreEqual (string.Empty, cn.DataSource, "#4");
489 Assert.AreEqual (8000, cn.PacketSize, "#5");
490 // https://github.com/dotnet/corefx/issues/22871
491 // Assert.IsTrue (string.Compare (Environment.MachineName, cn.WorkstationId, true) == 0, "#6");
492 Assert.AreEqual (ConnectionState.Closed, cn.State, "#7");
493 cn.Dispose ();
495 cn = new SqlConnection ();
496 cn.Dispose ();
499 [Test]
500 [Category("NotWorking")] //https://github.com/dotnet/corefx/issues/22882
501 #if FEATURE_NO_BSD_SOCKETS
502 [ExpectedException (typeof (PlatformNotSupportedException))]
503 #endif
504 public void GetSchema_Connection_Closed ()
506 SqlConnection cn = new SqlConnection ();
508 try {
509 cn.GetSchema ();
510 Assert.Fail ("#A1");
511 } catch (InvalidOperationException ex) {
512 // Invalid operation. The connection is closed
513 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
514 Assert.IsNull (ex.InnerException, "#B3");
515 Assert.IsNotNull (ex.Message, "#B4");
518 try {
519 cn.GetSchema ("Tables");
520 Assert.Fail ("#B1");
521 } catch (InvalidOperationException ex) {
522 // Invalid operation. The connection is closed
523 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
524 Assert.IsNull (ex.InnerException, "#B3");
525 Assert.IsNotNull (ex.Message, "#B4");
528 try {
529 cn.GetSchema ((string) null);
530 Assert.Fail ("#C1");
531 } catch (InvalidOperationException ex) {
532 // Invalid operation. The connection is closed
533 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
534 Assert.IsNull (ex.InnerException, "#C3");
535 Assert.IsNotNull (ex.Message, "#C4");
538 try {
539 cn.GetSchema ("Tables", new string [] { "master" });
540 Assert.Fail ("#D1");
541 } catch (InvalidOperationException ex) {
542 // Invalid operation. The connection is closed
543 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
544 Assert.IsNull (ex.InnerException, "#D3");
545 Assert.IsNotNull (ex.Message, "#D4");
548 try {
549 cn.GetSchema ((string) null, new string [] { "master" });
550 Assert.Fail ("#E1");
551 } catch (InvalidOperationException ex) {
552 // Invalid operation. The connection is closed
553 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E2");
554 Assert.IsNull (ex.InnerException, "#E3");
555 Assert.IsNotNull (ex.Message, "#E4");
558 try {
559 cn.GetSchema ("Tables", (string []) null);
560 Assert.Fail ("#F1");
561 } catch (InvalidOperationException ex) {
562 // Invalid operation. The connection is closed
563 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#F2");
564 Assert.IsNull (ex.InnerException, "#F3");
565 Assert.IsNotNull (ex.Message, "#F4");
568 try {
569 cn.GetSchema ((string) null, (string []) null);
570 Assert.Fail ("#G1");
571 } catch (InvalidOperationException ex) {
572 // Invalid operation. The connection is closed
573 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#G2");
574 Assert.IsNull (ex.InnerException, "#G3");
575 Assert.IsNotNull (ex.Message, "#G4");
579 [Test]
580 [Category("NotWorking")] // https://github.com/dotnet/corefx/issues/22474
581 #if FEATURE_NO_BSD_SOCKETS
582 [ExpectedException (typeof (PlatformNotSupportedException))]
583 #endif
584 public void ConnectionString_AsynchronousProcessing ()
586 SqlConnection cn = new SqlConnection ();
587 cn.ConnectionString = "Asynchronous Processing=False";
588 cn.ConnectionString = "Async=True";
591 [Test]
592 [Category("NotWorking")] // https://github.com/dotnet/corefx/issues/22879
593 #if FEATURE_NO_BSD_SOCKETS
594 [ExpectedException (typeof (PlatformNotSupportedException))]
595 #endif
596 public void ConnectionString_ConnectTimeout ()
598 SqlConnection cn = new SqlConnection ();
599 cn.ConnectionString = "Connection Timeout=45";
600 Assert.AreEqual (45, cn.ConnectionTimeout, "#1");
601 cn.ConnectionString = "Connect Timeout=40";
602 Assert.AreEqual (40, cn.ConnectionTimeout, "#2");
603 cn.ConnectionString = "Timeout=";
604 Assert.AreEqual (15, cn.ConnectionTimeout, "#3");
605 cn.ConnectionString = "Timeout=2147483647";
606 Assert.AreEqual (int.MaxValue, cn.ConnectionTimeout, "#4");
607 cn.ConnectionString = "Timeout=0";
608 Assert.AreEqual (0, cn.ConnectionTimeout, "#5");
611 [Test]
612 #if FEATURE_NO_BSD_SOCKETS
613 [ExpectedException (typeof (PlatformNotSupportedException))]
614 #endif
615 public void ConnectionString_ConnectTimeout_Invalid ()
617 SqlConnection cn = new SqlConnection ();
619 // negative number
620 try {
621 cn.ConnectionString = "Connection timeout=-1";
622 Assert.Fail ("#A1");
623 } catch (ArgumentException ex) {
624 // Invalid value for key 'connect timeout'
625 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
626 Assert.IsNull (ex.InnerException, "#A3");
627 Assert.IsNotNull (ex.Message, "#A4");
628 Assert.IsTrue (ex.Message.IndexOf ("'connect timeout'") != -1, "#A5:" + ex.Message);
629 Assert.IsNull (ex.ParamName, "#A6");
632 // invalid number
633 try {
634 cn.ConnectionString = "connect Timeout=BB";
635 Assert.Fail ("#B1");
636 } catch (ArgumentException ex) {
637 // Invalid value for key 'connect timeout'
638 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
639 Assert.IsNotNull (ex.InnerException, "#B3");
640 Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#B4");
641 Assert.IsNotNull (ex.Message, "#B5");
642 Assert.IsTrue (ex.Message.IndexOf ("'connect timeout'") != -1, "#B6:" + ex.Message);
643 Assert.IsNull (ex.ParamName, "#B7");
645 // Input string was not in a correct format
646 FormatException fe = (FormatException) ex.InnerException;
647 Assert.IsNull (fe.InnerException, "#B8");
648 Assert.IsNotNull (fe.Message, "#B9");
651 // overflow
652 try {
653 cn.ConnectionString = "timeout=2147483648";
654 Assert.Fail ("#C1");
655 } catch (ArgumentException ex) {
656 // Invalid value for key 'connect timeout'
657 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
658 Assert.IsNotNull (ex.InnerException, "#C3");
659 Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#C4");
660 Assert.IsNotNull (ex.Message, "#C5");
661 Assert.IsTrue (ex.Message.IndexOf ("'connect timeout'") != -1, "#C6:" + ex.Message);
662 Assert.IsNull (ex.ParamName, "#C7");
664 // Value was either too large or too small for an Int32
665 OverflowException oe = (OverflowException) ex.InnerException;
666 Assert.IsNull (oe.InnerException, "#C8");
667 Assert.IsNotNull (oe.Message, "#C9");
671 [Test]
672 #if FEATURE_NO_BSD_SOCKETS
673 [ExpectedException (typeof (PlatformNotSupportedException))]
674 #endif
675 public void ConnectionString_Database_Synonyms ()
677 SqlConnection cn = null;
679 cn = new SqlConnection ();
680 cn.ConnectionString = "Initial Catalog=db";
681 Assert.AreEqual ("db", cn.Database);
683 cn = new SqlConnection ();
684 cn.ConnectionString = "Database=db";
685 Assert.AreEqual ("db", cn.Database);
688 [Test]
689 #if FEATURE_NO_BSD_SOCKETS
690 [ExpectedException (typeof (PlatformNotSupportedException))]
691 #endif
692 public void ConnectionString_DataSource_Synonyms ()
694 SqlConnection cn = null;
696 cn = new SqlConnection ();
697 cn.ConnectionString = "Data Source=server";
698 Assert.AreEqual ("server", cn.DataSource);
700 cn = new SqlConnection ();
701 cn.ConnectionString = "addr=server";
702 Assert.AreEqual ("server", cn.DataSource);
704 cn = new SqlConnection ();
705 cn.ConnectionString = "address=server";
706 Assert.AreEqual ("server", cn.DataSource);
708 cn = new SqlConnection ();
709 cn.ConnectionString = "network address=server";
710 Assert.AreEqual ("server", cn.DataSource);
712 cn = new SqlConnection ();
713 cn.ConnectionString = "server=server";
714 Assert.AreEqual ("server", cn.DataSource);
717 [Test]
718 #if FEATURE_NO_BSD_SOCKETS
719 [ExpectedException (typeof (PlatformNotSupportedException))]
720 #endif
721 public void ConnectionString_MaxPoolSize ()
723 SqlConnection cn = new SqlConnection ();
724 cn.ConnectionString = "Max Pool Size=2147483647";
725 cn.ConnectionString = "Max Pool Size=1";
726 cn.ConnectionString = "Max Pool Size=500";
729 [Test]
730 #if FEATURE_NO_BSD_SOCKETS
731 [ExpectedException (typeof (PlatformNotSupportedException))]
732 #endif
733 public void ConnectionString_MaxPoolSize_Invalid ()
735 SqlConnection cn = new SqlConnection ();
737 // negative number
738 try {
739 cn.ConnectionString = "Max Pool Size=-1";
740 Assert.Fail ("#A1");
741 } catch (ArgumentException ex) {
742 // Invalid value for key 'max pool size'
743 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
744 Assert.IsNull (ex.InnerException, "#A3");
745 Assert.IsNotNull (ex.Message, "#A4");
746 Assert.IsTrue (ex.Message.IndexOf ("'max pool size'") != -1, "#A5:" + ex.Message);
747 Assert.IsNull (ex.ParamName, "#A6");
750 // invalid number
751 try {
752 cn.ConnectionString = "max Pool size=BB";
753 Assert.Fail ("#B1");
754 } catch (ArgumentException ex) {
755 // Invalid value for key 'max pool size'
756 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
757 Assert.IsNotNull (ex.InnerException, "#B3");
758 Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#B4");
759 Assert.IsNotNull (ex.Message, "#B5");
760 Assert.IsTrue (ex.Message.IndexOf ("'max pool size'") != -1, "#B6:" + ex.Message);
761 Assert.IsNull (ex.ParamName, "#B7");
763 // Input string was not in a correct format
764 FormatException fe = (FormatException) ex.InnerException;
765 Assert.IsNull (fe.InnerException, "#B8");
766 Assert.IsNotNull (fe.Message, "#B9");
769 // overflow
770 try {
771 cn.ConnectionString = "max pool size=2147483648";
772 Assert.Fail ("#C1");
773 } catch (ArgumentException ex) {
774 // Invalid value for key 'max pool size'
775 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
776 Assert.IsNotNull (ex.InnerException, "#C3");
777 Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#C4");
778 Assert.IsNotNull (ex.Message, "#C5");
779 Assert.IsTrue (ex.Message.IndexOf ("'max pool size'") != -1, "#C6:" + ex.Message);
780 Assert.IsNull (ex.ParamName, "#C7");
782 // Value was either too large or too small for an Int32
783 OverflowException oe = (OverflowException) ex.InnerException;
784 Assert.IsNull (oe.InnerException, "#C8");
785 Assert.IsNotNull (oe.Message, "#C9");
788 // less than minimum (1)
789 try {
790 cn.ConnectionString = "Min Pool Size=0;Max Pool Size=0";
791 Assert.Fail ("#D1");
792 } catch (ArgumentException ex) {
793 // Invalid value for key 'max pool size'
794 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
795 Assert.IsNull (ex.InnerException, "#D3");
796 Assert.IsNotNull (ex.Message, "#D4");
797 Assert.IsTrue (ex.Message.IndexOf ("'max pool size'") != -1, "#D5:" + ex.Message);
798 Assert.IsNull (ex.ParamName, "#D6");
801 // less than min pool size
802 try {
803 cn.ConnectionString = "Min Pool Size=5;Max Pool Size=4";
804 Assert.Fail ("#E1");
805 } catch (ArgumentException ex) {
806 // Invalid min or max pool size values, min
807 // pool size cannot be greater than the max
808 // pool size
809 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#E2");
810 Assert.IsNull (ex.InnerException, "#E3");
811 Assert.IsNotNull (ex.Message, "#E4");
812 Assert.IsNull (ex.ParamName, "#E5");
816 [Test]
817 #if FEATURE_NO_BSD_SOCKETS
818 [ExpectedException (typeof (PlatformNotSupportedException))]
819 #endif
820 public void ConnectionString_MinPoolSize ()
822 SqlConnection cn = new SqlConnection ();
823 cn.ConnectionString = "min Pool size=0";
824 cn.ConnectionString = "Min Pool size=100";
825 cn.ConnectionString = "Min Pool Size=2147483647;Max Pool Size=2147483647";
828 [Test]
829 #if FEATURE_NO_BSD_SOCKETS
830 [ExpectedException (typeof (PlatformNotSupportedException))]
831 #endif
832 public void ConnectionString_MinPoolSize_Invalid ()
834 SqlConnection cn = new SqlConnection ();
836 // negative number
837 try {
838 cn.ConnectionString = "Min Pool Size=-1";
839 Assert.Fail ("#A1");
840 } catch (ArgumentException ex) {
841 // Invalid value for key 'min pool size'
842 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
843 Assert.IsNull (ex.InnerException, "#A3");
844 Assert.IsNotNull (ex.Message, "#A4");
845 Assert.IsTrue (ex.Message.IndexOf ("'min pool size'") != -1, "#A5:" + ex.Message);
846 Assert.IsNull (ex.ParamName, "#A6");
849 // invalid number
850 try {
851 cn.ConnectionString = "min Pool size=BB";
852 Assert.Fail ("#B1");
853 } catch (ArgumentException ex) {
854 // Invalid value for key 'min pool size'
855 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
856 Assert.IsNotNull (ex.InnerException, "#B3");
857 Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#B4");
858 Assert.IsNotNull (ex.Message, "#B5");
859 Assert.IsTrue (ex.Message.IndexOf ("'min pool size'") != -1, "#B6:" + ex.Message);
860 Assert.IsNull (ex.ParamName, "#B7");
862 // Input string was not in a correct format
863 FormatException fe = (FormatException) ex.InnerException;
864 Assert.IsNull (fe.InnerException, "#B8");
865 Assert.IsNotNull (fe.Message, "#B9");
868 // overflow
869 try {
870 cn.ConnectionString = "min pool size=2147483648";
871 Assert.Fail ("#C1");
872 } catch (ArgumentException ex) {
873 // Invalid value for key 'min pool size'
874 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
875 Assert.IsNotNull (ex.InnerException, "#C3");
876 Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#C4");
877 Assert.IsNotNull (ex.Message, "#C5");
878 Assert.IsTrue (ex.Message.IndexOf ("'min pool size'") != -1, "#C6:" + ex.Message);
879 Assert.IsNull (ex.ParamName, "#C7");
881 // Value was either too large or too small for an Int32
882 OverflowException oe = (OverflowException) ex.InnerException;
883 Assert.IsNull (oe.InnerException, "#C8");
884 Assert.IsNotNull (oe.Message, "#C9");
888 [Test]
889 #if FEATURE_NO_BSD_SOCKETS
890 [ExpectedException (typeof (PlatformNotSupportedException))]
891 #endif
892 public void ConnectionString_MultipleActiveResultSets ()
894 SqlConnection cn = new SqlConnection ();
895 cn.ConnectionString = "MultipleActiveResultSets=true";
898 [Test]
899 #if FEATURE_NO_BSD_SOCKETS
900 [ExpectedException (typeof (PlatformNotSupportedException))]
901 #endif
902 public void ConnectionString_MultipleActiveResultSets_Invalid ()
904 SqlConnection cn = new SqlConnection ();
905 try {
906 cn.ConnectionString = "MultipleActiveResultSets=1";
907 Assert.Fail ("#1");
908 } catch (ArgumentException ex) {
909 // Invalid value for key 'multipleactiveresultsets'
910 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
911 Assert.IsNull (ex.InnerException, "#3");
912 Assert.IsNotNull (ex.Message, "#4");
913 Assert.IsTrue (ex.Message.IndexOf ("'multipleactiveresultsets'") != -1, "#5:" + ex.Message);
914 Assert.IsNull (ex.ParamName, "#6");
918 [Test]
919 [Category("NotWorking")] // https://github.com/dotnet/corefx/issues/22474
920 #if FEATURE_NO_BSD_SOCKETS
921 [ExpectedException (typeof (PlatformNotSupportedException))]
922 #endif
923 public void ConnectionString_NetworkLibrary_Synonyms ()
925 SqlConnection cn = new SqlConnection ();
926 cn.ConnectionString = "Net=DBMSSOCN";
927 cn.ConnectionString = "Network=DBMSSOCN";
928 cn.ConnectionString = "Network library=DBMSSOCN";
931 [Test]
932 [Category("NotWorking")] // https://github.com/dotnet/corefx/issues/22879
933 #if FEATURE_NO_BSD_SOCKETS
934 [ExpectedException (typeof (PlatformNotSupportedException))]
935 #endif
936 public void ConnectionString_PacketSize ()
938 SqlConnection cn = new SqlConnection ();
939 cn.ConnectionString = "Packet Size=1024";
940 Assert.AreEqual (1024, cn.PacketSize, "#1");
941 cn.ConnectionString = "packet SizE=533";
942 Assert.AreEqual (533, cn.PacketSize, "#2");
943 cn.ConnectionString = "packet SizE=512";
944 Assert.AreEqual (512, cn.PacketSize, "#3");
945 cn.ConnectionString = "packet SizE=32768";
946 Assert.AreEqual (32768, cn.PacketSize, "#4");
947 cn.ConnectionString = "packet Size=";
948 Assert.AreEqual (8000, cn.PacketSize, "#5");
951 [Test]
952 #if FEATURE_NO_BSD_SOCKETS
953 [ExpectedException (typeof (PlatformNotSupportedException))]
954 #endif
955 public void ConnectionString_PacketSize_Invalid ()
957 SqlConnection cn = new SqlConnection ();
959 // invalid packet size (< minimum)
960 try {
961 cn.ConnectionString = "Packet Size=511";
962 Assert.Fail ("#A1");
963 } catch (ArgumentException ex) {
964 // Invalid 'Packet Size'. The value must be an
965 // integer >= 512 and <= 32768
966 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
967 Assert.IsNull (ex.InnerException, "#A3");
968 Assert.IsNotNull (ex.Message, "#A4");
969 Assert.IsTrue (ex.Message.IndexOf ("'Packet Size'") != -1, "#A5:" + ex.Message);
970 Assert.IsNull (ex.ParamName, "#A6");
973 // invalid packet size (> maximum)
974 try {
975 cn.ConnectionString = "packet SIze=32769";
976 Assert.Fail ("#B1");
977 } catch (ArgumentException ex) {
978 // Invalid 'Packet Size'. The value must be an
979 // integer >= 512 and <= 32768
980 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
981 Assert.IsNull (ex.InnerException, "#B3");
982 Assert.IsNotNull (ex.Message, "#B4");
983 Assert.IsTrue (ex.Message.IndexOf ("'Packet Size'") != -1, "#B5:" + ex.Message);
984 Assert.IsNull (ex.ParamName, "#B6");
987 // overflow
988 try {
989 cn.ConnectionString = "packet SIze=2147483648";
990 Assert.Fail ("#C1");
991 } catch (ArgumentException ex) {
992 // Invalid value for key 'packet size'
993 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
994 Assert.IsNotNull (ex.InnerException, "#C3");
995 Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#C4");
996 Assert.IsNotNull (ex.Message, "#C5");
997 Assert.IsTrue (ex.Message.IndexOf ("'packet size'") != -1, "#C6:" + ex.Message);
998 Assert.IsNull (ex.ParamName, "#C7");
1000 // Value was either too large or too small for an Int32
1001 OverflowException oe = (OverflowException) ex.InnerException;
1002 Assert.IsNull (oe.InnerException, "#C8");
1003 Assert.IsNotNull (oe.Message, "#C9");
1007 [Test]
1008 #if FEATURE_NO_BSD_SOCKETS
1009 [ExpectedException (typeof (PlatformNotSupportedException))]
1010 #endif
1011 public void ConnectionString_Password_Synonyms ()
1013 SqlConnection cn = new SqlConnection ();
1014 cn.ConnectionString = "Password=scrambled";
1015 cn.ConnectionString = "Pwd=scrambled";
1018 [Test]
1019 #if FEATURE_NO_BSD_SOCKETS
1020 [ExpectedException (typeof (PlatformNotSupportedException))]
1021 #endif
1022 public void ConnectionString_PersistSecurityInfo_Synonyms ()
1024 SqlConnection cn = new SqlConnection ();
1025 cn.ConnectionString = "Persist Security Info=true";
1026 cn.ConnectionString = "PersistSecurityInfo=true";
1029 [Test]
1030 #if FEATURE_NO_BSD_SOCKETS
1031 [ExpectedException (typeof (PlatformNotSupportedException))]
1032 #endif
1033 public void ConnectionString_UserID_Synonyms ()
1035 SqlConnection cn = new SqlConnection ();
1036 cn.ConnectionString = "User Id=test";
1037 cn.ConnectionString = "User=test";
1038 cn.ConnectionString = "Uid=test";
1041 [Test]
1042 #if FEATURE_NO_BSD_SOCKETS
1043 [ExpectedException (typeof (PlatformNotSupportedException))]
1044 #endif
1045 public void ConnectionString_UserInstance ()
1047 SqlConnection cn = new SqlConnection ();
1048 cn.ConnectionString = "User Instance=true";
1051 [Test]
1052 #if FEATURE_NO_BSD_SOCKETS
1053 [ExpectedException (typeof (PlatformNotSupportedException))]
1054 #endif
1055 public void ConnectionString_UserInstance_Invalid ()
1057 SqlConnection cn = new SqlConnection ();
1058 try {
1059 cn.ConnectionString = "User Instance=1";
1060 Assert.Fail ("#1");
1061 } catch (ArgumentException ex) {
1062 // Invalid value for key 'user instance'
1063 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1064 Assert.IsNull (ex.InnerException, "#3");
1065 Assert.IsNotNull (ex.Message, "#4");
1066 Assert.IsTrue (ex.Message.IndexOf ("'user instance'") != -1, "#5:" + ex.Message);
1067 Assert.IsNull (ex.ParamName, "#6");
1071 [Test]
1072 [Category("NotWorking")] // https://github.com/dotnet/corefx/issues/22474
1073 #if FEATURE_NO_BSD_SOCKETS
1074 [ExpectedException (typeof (PlatformNotSupportedException))]
1075 #endif
1076 public void ConnectionString_OtherKeywords ()
1078 SqlConnection cn = new SqlConnection ();
1079 cn.ConnectionString = "Application Name=test";
1080 cn.ConnectionString = "App=test";
1081 cn.ConnectionString = "Connection Reset=true";
1082 cn.ConnectionString = "Current Language=test";
1083 cn.ConnectionString = "Language=test";
1084 cn.ConnectionString = "Encrypt=false";
1085 //cn.ConnectionString = "Encrypt=true";
1086 //cn.ConnectionString = "Enlist=false";
1087 cn.ConnectionString = "Enlist=true";
1088 cn.ConnectionString = "Integrated Security=true";
1089 cn.ConnectionString = "Trusted_connection=true";
1090 cn.ConnectionString = "Max Pool Size=10";
1091 cn.ConnectionString = "Min Pool Size=10";
1092 cn.ConnectionString = "Pooling=true";
1093 cn.ConnectionString = "attachdbfilename=dunno";
1094 cn.ConnectionString = "extended properties=dunno";
1095 cn.ConnectionString = "initial file name=dunno";
1098 [Test]
1099 #if FEATURE_NO_BSD_SOCKETS
1100 [ExpectedException (typeof (PlatformNotSupportedException))]
1101 #endif
1102 public void Open_ConnectionString_Empty ()
1104 SqlConnection cn = new SqlConnection ();
1105 cn.ConnectionString = string.Empty;
1107 try {
1108 cn.Open ();
1109 Assert.Fail ("#1");
1110 } catch (InvalidOperationException ex) {
1111 // The ConnectionString property has not been
1112 // initialized
1113 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1114 Assert.IsNull (ex.InnerException, "#3");
1115 Assert.IsNotNull (ex.Message, "#4");
1119 [Test]
1120 #if FEATURE_NO_BSD_SOCKETS
1121 [ExpectedException (typeof (PlatformNotSupportedException))]
1122 #endif
1123 public void Open_ConnectionString_Null ()
1125 SqlConnection cn = new SqlConnection ();
1126 cn.ConnectionString = null;
1128 try {
1129 cn.Open ();
1130 Assert.Fail ("#1");
1131 } catch (InvalidOperationException ex) {
1132 // The ConnectionString property has not been
1133 // initialized
1134 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1135 Assert.IsNull (ex.InnerException, "#3");
1136 Assert.IsNotNull (ex.Message, "#4");
1140 [Test]
1141 #if FEATURE_NO_BSD_SOCKETS
1142 [ExpectedException (typeof (PlatformNotSupportedException))]
1143 #endif
1144 public void Open_ConnectionString_Whitespace ()
1146 SqlConnection cn = new SqlConnection ();
1147 cn.ConnectionString = " ";
1149 try {
1150 cn.Open ();
1151 Assert.Fail ("#1");
1152 } catch (InvalidOperationException ex) {
1153 // The ConnectionString property has not been
1154 // initialized
1155 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1156 Assert.IsNull (ex.InnerException, "#3");
1157 Assert.IsNotNull (ex.Message, "#4");
1161 [Test]
1162 #if FEATURE_NO_BSD_SOCKETS
1163 [ExpectedException (typeof (PlatformNotSupportedException))]
1164 #endif
1165 public void ServerVersion_Connection_Closed ()
1167 SqlConnection cn = new SqlConnection ();
1168 try {
1169 Assert.Fail ("#A1:" + cn.ServerVersion);
1170 } catch (InvalidOperationException ex) {
1171 // Invalid operation. The connection is closed
1172 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1173 Assert.IsNull (ex.InnerException, "#A3");
1174 Assert.IsNotNull (ex.Message, "#A4");
1177 cn = new SqlConnection ("server=SQLSRV; database=Mono;");
1178 try {
1179 Assert.Fail ("#B1:" + cn.ServerVersion);
1180 } catch (InvalidOperationException ex) {
1181 // Invalid operation. The connection is closed
1182 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
1183 Assert.IsNull (ex.InnerException, "#B3");
1184 Assert.IsNotNull (ex.Message, "#B4");