2 // SqlConnectionTest.cs - NUnit Test Cases for testing the
5 // Gert Driesen (drieseng@users.sourceforge.net)
7 // Copyright (c) 2004 Novell Inc., and the individuals listed
8 // on the ChangeLog entries.
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.
32 using System
.Data
.SqlClient
;
34 using NUnit
.Framework
;
36 namespace MonoTests
.System
.Data
.SqlClient
39 public class SqlConnectionTest
41 [Test
] // SqlConnection ()
42 #if FEATURE_NO_BSD_SOCKETS
43 [ExpectedException (typeof (PlatformNotSupportedException
))]
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 Assert
.IsTrue (string.Compare (Environment
.MachineName
, cn
.WorkstationId
, true) == 0, "#11");
62 [Test
] // SqlConnection (string)
63 #if FEATURE_NO_BSD_SOCKETS
64 [ExpectedException (typeof (PlatformNotSupportedException
))]
66 public void Constructor2 ()
68 string connectionString
= "server=SQLSRV; database=Mono;";
70 SqlConnection cn
= new SqlConnection (connectionString
);
71 Assert
.AreEqual (connectionString
, cn
.ConnectionString
, "#A1");
72 Assert
.AreEqual (15, cn
.ConnectionTimeout
, "#A2");
73 Assert
.IsNull (cn
.Container
, "#A3");
74 Assert
.AreEqual ("Mono", cn
.Database
, "#A4");
75 Assert
.AreEqual ("SQLSRV", cn
.DataSource
, "#A5");
76 Assert
.IsFalse (cn
.FireInfoMessageEventOnUserErrors
, "#A6");
77 Assert
.AreEqual (8000, cn
.PacketSize
, "#A7");
78 Assert
.IsNull (cn
.Site
, "#A8");
79 Assert
.AreEqual (ConnectionState
.Closed
, cn
.State
, "#A9");
80 Assert
.IsFalse (cn
.StatisticsEnabled
, "#A10");
81 Assert
.IsTrue (string.Compare (Environment
.MachineName
, cn
.WorkstationId
, true) == 0, "#A11");
83 cn
= new SqlConnection ((string) null);
84 Assert
.AreEqual (string.Empty
, cn
.ConnectionString
, "#B1");
85 Assert
.AreEqual (15, cn
.ConnectionTimeout
, "#B2");
86 Assert
.IsNull (cn
.Container
, "#B3");
87 Assert
.AreEqual (string.Empty
, cn
.Database
, "#B4");
88 Assert
.AreEqual (string.Empty
, cn
.DataSource
, "#B5");
89 Assert
.IsFalse (cn
.FireInfoMessageEventOnUserErrors
, "#B6");
90 Assert
.AreEqual (8000, cn
.PacketSize
, "#B7");
91 Assert
.IsNull (cn
.Site
, "#B8");
92 Assert
.AreEqual (ConnectionState
.Closed
, cn
.State
, "#B9");
93 Assert
.IsFalse (cn
.StatisticsEnabled
, "#B10");
94 Assert
.IsTrue (string.Compare (Environment
.MachineName
, cn
.WorkstationId
, true) == 0, "#B11");
98 #if FEATURE_NO_BSD_SOCKETS
99 [ExpectedException (typeof (PlatformNotSupportedException
))]
101 public void Constructor2_ConnectionString_Invalid ()
104 new SqlConnection ("InvalidConnectionString");
106 } catch (ArgumentException ex
) {
107 // Format of the initialization string does
108 // not conform to specification starting at
110 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#A2");
111 Assert
.IsNull (ex
.InnerException
, "#A3");
112 Assert
.IsNotNull (ex
.Message
, "#A4");
113 Assert
.IsNull (ex
.ParamName
, "#A5");
118 new SqlConnection ("invalidKeyword=10");
120 } catch (ArgumentException ex
) {
121 // Keyword not supported: 'invalidkeyword'
122 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#B2");
123 Assert
.IsNull (ex
.InnerException
, "#B3");
124 Assert
.IsNotNull (ex
.Message
, "#B4");
125 Assert
.IsTrue (ex
.Message
.IndexOf ("'invalidkeyword'") != -1, "#B5");
126 Assert
.IsNull (ex
.ParamName
, "#B6");
129 // invalid packet size (< minimum)
131 new SqlConnection ("Packet Size=511");
133 } catch (ArgumentException ex
) {
134 // Invalid 'Packet Size'. The value must be an
135 // integer >= 512 and <= 32768
136 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#C2");
137 Assert
.IsNull (ex
.InnerException
, "#C3");
138 Assert
.IsNotNull (ex
.Message
, "#C4");
139 Assert
.IsNull (ex
.ParamName
, "#C5");
142 // invalid packet size (> maximum)
144 new SqlConnection ("Packet Size=32769");
146 } catch (ArgumentException ex
) {
147 // Invalid 'Packet Size'. The value must be an
148 // integer >= 512 and <= 32768
149 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#D2");
150 Assert
.IsNull (ex
.InnerException
, "#D3");
151 Assert
.IsNotNull (ex
.Message
, "#D4");
152 Assert
.IsNull (ex
.ParamName
, "#D5");
155 // negative connect timeout
157 new SqlConnection ("Connect Timeout=-1");
159 } catch (ArgumentException ex
) {
160 // Invalid value for key 'connect timeout'
161 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#E2");
162 Assert
.IsNull (ex
.InnerException
, "#E3");
163 Assert
.IsNotNull (ex
.Message
, "#E4");
164 Assert
.IsNull (ex
.ParamName
, "#E5");
167 // negative max pool size
169 new SqlConnection ("Max Pool Size=-1");
171 } catch (ArgumentException ex
) {
172 // Invalid value for key 'max pool size'
173 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#F2");
174 Assert
.IsNull (ex
.InnerException
, "#F3");
175 Assert
.IsNotNull (ex
.Message
, "#F4");
176 Assert
.IsNull (ex
.ParamName
, "#F5");
179 // negative min pool size
181 new SqlConnection ("Min Pool Size=-1");
183 } catch (ArgumentException ex
) {
184 // Invalid value for key 'min pool size'
185 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#G2");
186 Assert
.IsNull (ex
.InnerException
, "#G3");
187 Assert
.IsNotNull (ex
.Message
, "#G4");
188 Assert
.IsNull (ex
.ParamName
, "#G5");
193 #if FEATURE_NO_BSD_SOCKETS
194 [ExpectedException (typeof (PlatformNotSupportedException
))]
196 public void BeginTransaction_Connection_Closed ()
198 SqlConnection cn
= new SqlConnection ();
201 cn
.BeginTransaction ();
203 } catch (InvalidOperationException ex
) {
204 // Invalid operation. The connection is closed
205 Assert
.AreEqual (typeof (InvalidOperationException
), ex
.GetType (), "#A2");
206 Assert
.IsNull (ex
.InnerException
, "#A3");
207 Assert
.IsNotNull (ex
.Message
, "#A4");
211 cn
.BeginTransaction ((IsolationLevel
) 666);
213 } catch (InvalidOperationException ex
) {
214 // Invalid operation. The connection is closed
215 Assert
.AreEqual (typeof (InvalidOperationException
), ex
.GetType (), "#B2");
216 Assert
.IsNull (ex
.InnerException
, "#B3");
217 Assert
.IsNotNull (ex
.Message
, "#B4");
221 cn
.BeginTransaction (IsolationLevel
.Serializable
);
223 } catch (InvalidOperationException ex
) {
224 // Invalid operation. The connection is closed
225 Assert
.AreEqual (typeof (InvalidOperationException
), ex
.GetType (), "#C2");
226 Assert
.IsNull (ex
.InnerException
, "#C3");
227 Assert
.IsNotNull (ex
.Message
, "#C4");
231 cn
.BeginTransaction ("trans");
233 } catch (InvalidOperationException ex
) {
234 // Invalid operation. The connection is closed
235 Assert
.AreEqual (typeof (InvalidOperationException
), ex
.GetType (), "#D2");
236 Assert
.IsNull (ex
.InnerException
, "#D3");
237 Assert
.IsNotNull (ex
.Message
, "#D4");
241 cn
.BeginTransaction ((IsolationLevel
) 666, "trans");
243 } catch (InvalidOperationException ex
) {
244 // Invalid operation. The connection is closed
245 Assert
.AreEqual (typeof (InvalidOperationException
), ex
.GetType (), "#E2");
246 Assert
.IsNull (ex
.InnerException
, "#E3");
247 Assert
.IsNotNull (ex
.Message
, "#E4");
251 cn
.BeginTransaction (IsolationLevel
.Serializable
, "trans");
253 } catch (InvalidOperationException ex
) {
254 // Invalid operation. The connection is closed
255 Assert
.AreEqual (typeof (InvalidOperationException
), ex
.GetType (), "#F2");
256 Assert
.IsNull (ex
.InnerException
, "#F3");
257 Assert
.IsNotNull (ex
.Message
, "#F4");
262 #if FEATURE_NO_BSD_SOCKETS
263 [ExpectedException (typeof (PlatformNotSupportedException
))]
265 public void ChangeDatabase_Connection_Closed ()
267 SqlConnection cn
= new SqlConnection ();
268 cn
.ConnectionString
= "server=SQLSRV";
271 cn
.ChangeDatabase ("database");
273 } catch (InvalidOperationException ex
) {
274 // Invalid operation. The connection is closed
275 Assert
.AreEqual (typeof (InvalidOperationException
), ex
.GetType (), "#2");
276 Assert
.IsNull (ex
.InnerException
, "#3");
277 Assert
.IsNotNull (ex
.Message
, "#4");
282 #if FEATURE_NO_BSD_SOCKETS
283 [ExpectedException (typeof (PlatformNotSupportedException
))]
285 public void ChangePassword_ConnectionString_Empty ()
288 SqlConnection
.ChangePassword (string.Empty
, "mono");
290 } catch (ArgumentNullException ex
) {
291 Assert
.AreEqual (typeof (ArgumentNullException
), ex
.GetType (), "#2");
292 Assert
.IsNull (ex
.InnerException
, "#3");
293 Assert
.IsNotNull (ex
.Message
, "#4");
294 Assert
.IsNotNull (ex
.ParamName
, "#5");
295 Assert
.IsTrue (ex
.ParamName
.IndexOf ("'connectionString'") != -1, "#6");
300 #if FEATURE_NO_BSD_SOCKETS
301 [ExpectedException (typeof (PlatformNotSupportedException
))]
303 public void ChangePassword_ConnectionString_Null ()
306 SqlConnection
.ChangePassword ((string) null, "mono");
308 } catch (ArgumentNullException ex
) {
309 Assert
.AreEqual (typeof (ArgumentNullException
), ex
.GetType (), "#2");
310 Assert
.IsNull (ex
.InnerException
, "#3");
311 Assert
.IsNotNull (ex
.Message
, "#4");
312 Assert
.IsNotNull (ex
.ParamName
, "#5");
313 Assert
.IsTrue (ex
.ParamName
.IndexOf ("'connectionString'") != -1, "#6");
318 #if FEATURE_NO_BSD_SOCKETS
319 [ExpectedException (typeof (PlatformNotSupportedException
))]
321 public void ChangePassword_NewPassword_Empty ()
324 SqlConnection
.ChangePassword ("server=SQLSRV", string.Empty
);
326 } catch (ArgumentNullException ex
) {
327 Assert
.AreEqual (typeof (ArgumentNullException
), ex
.GetType (), "#2");
328 Assert
.IsNull (ex
.InnerException
, "#3");
329 Assert
.IsNotNull (ex
.Message
, "#4");
330 Assert
.IsNotNull (ex
.ParamName
, "#5");
331 Assert
.IsTrue (ex
.ParamName
.IndexOf ("'newPassword'") != -1, "#6");
336 #if FEATURE_NO_BSD_SOCKETS
337 [ExpectedException (typeof (PlatformNotSupportedException
))]
339 public void ChangePassword_NewPassword_ExceedMaxLength ()
342 SqlConnection
.ChangePassword ("server=SQLSRV",
343 new string ('d', 129));
345 } catch (ArgumentException ex
) {
346 // The length of argument 'newPassword' exceeds
347 // it's limit of '128'
348 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#2");
349 Assert
.IsNull (ex
.InnerException
, "#3");
350 Assert
.IsNotNull (ex
.Message
, "#4");
351 Assert
.IsTrue (ex
.Message
.IndexOf ("'newPassword'") != -1, "#5");
352 Assert
.IsTrue (ex
.Message
.IndexOf ("128") != -1, "#6");
353 Assert
.IsNull (ex
.ParamName
, "#7");
358 #if FEATURE_NO_BSD_SOCKETS
359 [ExpectedException (typeof (PlatformNotSupportedException
))]
361 public void ChangePassword_NewPassword_Null ()
364 SqlConnection
.ChangePassword ("server=SQLSRV", (string) null);
366 } catch (ArgumentNullException ex
) {
367 Assert
.AreEqual (typeof (ArgumentNullException
), ex
.GetType (), "#2");
368 Assert
.IsNull (ex
.InnerException
, "#3");
369 Assert
.IsNotNull (ex
.Message
, "#4");
370 Assert
.IsNotNull (ex
.ParamName
, "#5");
371 Assert
.IsTrue (ex
.ParamName
.IndexOf ("'newPassword'") != -1, "#6");
376 #if FEATURE_NO_BSD_SOCKETS
377 [ExpectedException (typeof (PlatformNotSupportedException
))]
379 public void ClearPool_Connection_Null ()
382 SqlConnection
.ClearPool ((SqlConnection
) null);
384 } catch (ArgumentNullException ex
) {
385 Assert
.AreEqual (typeof (ArgumentNullException
), ex
.GetType (), "#2");
386 Assert
.IsNull (ex
.InnerException
, "#3");
387 Assert
.IsNotNull (ex
.Message
, "#4");
388 Assert
.AreEqual ("connection", ex
.ParamName
, "#5");
393 #if FEATURE_NO_BSD_SOCKETS
394 [ExpectedException (typeof (PlatformNotSupportedException
))]
396 public void ConnectionString ()
398 SqlConnection cn
= new SqlConnection ();
399 cn
.ConnectionString
= "server=SQLSRV";
400 Assert
.AreEqual ("server=SQLSRV", cn
.ConnectionString
, "#1");
401 cn
.ConnectionString
= null;
402 Assert
.AreEqual (string.Empty
, cn
.ConnectionString
, "#2");
403 cn
.ConnectionString
= "server=SQLSRV";
404 Assert
.AreEqual ("server=SQLSRV", cn
.ConnectionString
, "#3");
405 cn
.ConnectionString
= string.Empty
;
406 Assert
.AreEqual (string.Empty
, cn
.ConnectionString
, "#4");
410 #if FEATURE_NO_BSD_SOCKETS
411 [ExpectedException (typeof (PlatformNotSupportedException
))]
413 public void ConnectionString_Value_Invalid ()
415 SqlConnection cn
= new SqlConnection ();
418 cn
.ConnectionString
= "InvalidConnectionString";
420 } catch (ArgumentException ex
) {
421 // Format of the initialization string does
422 // not conform to specification starting at
424 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#A2");
425 Assert
.IsNull (ex
.InnerException
, "#A3");
426 Assert
.IsNotNull (ex
.Message
, "#A4");
427 Assert
.IsNull (ex
.ParamName
, "#A5");
432 cn
.ConnectionString
= "invalidKeyword=10";
434 } catch (ArgumentException ex
) {
435 // Keyword not supported: 'invalidkeyword'
436 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#B2");
437 Assert
.IsNull (ex
.InnerException
, "#B3");
438 Assert
.IsNotNull (ex
.Message
, "#B4");
439 Assert
.IsTrue (ex
.Message
.IndexOf ("'invalidkeyword'") != -1, "#B5");
440 Assert
.IsNull (ex
.ParamName
, "#B6");
445 #if FEATURE_NO_BSD_SOCKETS
446 [ExpectedException (typeof (PlatformNotSupportedException
))]
448 public void CreateCommand ()
450 SqlConnection cn
= new SqlConnection ();
451 SqlCommand cmd
= cn
.CreateCommand ();
452 Assert
.IsNotNull (cmd
, "#1");
453 Assert
.AreEqual (string.Empty
, cmd
.CommandText
, "#2");
454 Assert
.AreEqual (30, cmd
.CommandTimeout
, "#3");
455 Assert
.AreEqual (CommandType
.Text
, cmd
.CommandType
, "#4");
456 Assert
.AreSame (cn
, cmd
.Connection
, "#5");
457 Assert
.IsNull (cmd
.Container
, "#6");
458 Assert
.IsTrue (cmd
.DesignTimeVisible
, "#7");
459 Assert
.IsNull (cmd
.Notification
, "#8");
460 Assert
.IsTrue (cmd
.NotificationAutoEnlist
, "#9");
461 Assert
.IsNotNull (cmd
.Parameters
, "#10");
462 Assert
.AreEqual (0, cmd
.Parameters
.Count
, "#11");
463 Assert
.IsNull (cmd
.Site
, "#12");
464 Assert
.IsNull (cmd
.Transaction
, "#13");
465 Assert
.AreEqual (UpdateRowSource
.Both
, cmd
.UpdatedRowSource
, "#14");
469 #if FEATURE_NO_BSD_SOCKETS
470 [ExpectedException (typeof (PlatformNotSupportedException
))]
472 public void Dispose ()
474 SqlConnection cn
= new SqlConnection ("Server=SQLSRV;Database=master;Timeout=25;Packet Size=512;Workstation ID=DUMMY");
477 Assert
.AreEqual (string.Empty
, cn
.ConnectionString
, "#1");
478 Assert
.AreEqual (15, cn
.ConnectionTimeout
, "#2");
479 Assert
.AreEqual (string.Empty
, cn
.Database
, "#3");
480 Assert
.AreEqual (string.Empty
, cn
.DataSource
, "#4");
481 Assert
.AreEqual (8000, cn
.PacketSize
, "#5");
482 Assert
.IsTrue (string.Compare (Environment
.MachineName
, cn
.WorkstationId
, true) == 0, "#6");
483 Assert
.AreEqual (ConnectionState
.Closed
, cn
.State
, "#7");
486 cn
= new SqlConnection ();
491 #if FEATURE_NO_BSD_SOCKETS
492 [ExpectedException (typeof (PlatformNotSupportedException
))]
494 public void GetSchema_Connection_Closed ()
496 SqlConnection cn
= new SqlConnection ();
501 } catch (InvalidOperationException ex
) {
502 // Invalid operation. The connection is closed
503 Assert
.AreEqual (typeof (InvalidOperationException
), ex
.GetType (), "#A2");
504 Assert
.IsNull (ex
.InnerException
, "#B3");
505 Assert
.IsNotNull (ex
.Message
, "#B4");
509 cn
.GetSchema ("Tables");
511 } catch (InvalidOperationException ex
) {
512 // Invalid operation. The connection is closed
513 Assert
.AreEqual (typeof (InvalidOperationException
), ex
.GetType (), "#B2");
514 Assert
.IsNull (ex
.InnerException
, "#B3");
515 Assert
.IsNotNull (ex
.Message
, "#B4");
519 cn
.GetSchema ((string) null);
521 } catch (InvalidOperationException ex
) {
522 // Invalid operation. The connection is closed
523 Assert
.AreEqual (typeof (InvalidOperationException
), ex
.GetType (), "#C2");
524 Assert
.IsNull (ex
.InnerException
, "#C3");
525 Assert
.IsNotNull (ex
.Message
, "#C4");
529 cn
.GetSchema ("Tables", new string [] { "master" }
);
531 } catch (InvalidOperationException ex
) {
532 // Invalid operation. The connection is closed
533 Assert
.AreEqual (typeof (InvalidOperationException
), ex
.GetType (), "#D2");
534 Assert
.IsNull (ex
.InnerException
, "#D3");
535 Assert
.IsNotNull (ex
.Message
, "#D4");
539 cn
.GetSchema ((string) null, new string [] { "master" }
);
541 } catch (InvalidOperationException ex
) {
542 // Invalid operation. The connection is closed
543 Assert
.AreEqual (typeof (InvalidOperationException
), ex
.GetType (), "#E2");
544 Assert
.IsNull (ex
.InnerException
, "#E3");
545 Assert
.IsNotNull (ex
.Message
, "#E4");
549 cn
.GetSchema ("Tables", (string []) null);
551 } catch (InvalidOperationException ex
) {
552 // Invalid operation. The connection is closed
553 Assert
.AreEqual (typeof (InvalidOperationException
), ex
.GetType (), "#F2");
554 Assert
.IsNull (ex
.InnerException
, "#F3");
555 Assert
.IsNotNull (ex
.Message
, "#F4");
559 cn
.GetSchema ((string) null, (string []) null);
561 } catch (InvalidOperationException ex
) {
562 // Invalid operation. The connection is closed
563 Assert
.AreEqual (typeof (InvalidOperationException
), ex
.GetType (), "#G2");
564 Assert
.IsNull (ex
.InnerException
, "#G3");
565 Assert
.IsNotNull (ex
.Message
, "#G4");
570 #if FEATURE_NO_BSD_SOCKETS
571 [ExpectedException (typeof (PlatformNotSupportedException
))]
573 public void ConnectionString_AsynchronousProcessing ()
575 SqlConnection cn
= new SqlConnection ();
576 cn
.ConnectionString
= "Asynchronous Processing=False";
577 cn
.ConnectionString
= "Async=True";
581 #if FEATURE_NO_BSD_SOCKETS
582 [ExpectedException (typeof (PlatformNotSupportedException
))]
584 public void ConnectionString_ConnectTimeout ()
586 SqlConnection cn
= new SqlConnection ();
587 cn
.ConnectionString
= "Connection Timeout=45";
588 Assert
.AreEqual (45, cn
.ConnectionTimeout
, "#1");
589 cn
.ConnectionString
= "Connect Timeout=40";
590 Assert
.AreEqual (40, cn
.ConnectionTimeout
, "#2");
591 cn
.ConnectionString
= "Timeout=";
592 Assert
.AreEqual (15, cn
.ConnectionTimeout
, "#3");
593 cn
.ConnectionString
= "Timeout=2147483647";
594 Assert
.AreEqual (int.MaxValue
, cn
.ConnectionTimeout
, "#4");
595 cn
.ConnectionString
= "Timeout=0";
596 Assert
.AreEqual (0, cn
.ConnectionTimeout
, "#5");
600 #if FEATURE_NO_BSD_SOCKETS
601 [ExpectedException (typeof (PlatformNotSupportedException
))]
603 public void ConnectionString_ConnectTimeout_Invalid ()
605 SqlConnection cn
= new SqlConnection ();
609 cn
.ConnectionString
= "Connection timeout=-1";
611 } catch (ArgumentException ex
) {
612 // Invalid value for key 'connect timeout'
613 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#A2");
614 Assert
.IsNull (ex
.InnerException
, "#A3");
615 Assert
.IsNotNull (ex
.Message
, "#A4");
616 Assert
.IsTrue (ex
.Message
.IndexOf ("'connect timeout'") != -1, "#A5:" + ex
.Message
);
617 Assert
.IsNull (ex
.ParamName
, "#A6");
622 cn
.ConnectionString
= "connect Timeout=BB";
624 } catch (ArgumentException ex
) {
625 // Invalid value for key 'connect timeout'
626 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#B2");
627 Assert
.IsNotNull (ex
.InnerException
, "#B3");
628 Assert
.AreEqual (typeof (FormatException
), ex
.InnerException
.GetType (), "#B4");
629 Assert
.IsNotNull (ex
.Message
, "#B5");
630 Assert
.IsTrue (ex
.Message
.IndexOf ("'connect timeout'") != -1, "#B6:" + ex
.Message
);
631 Assert
.IsNull (ex
.ParamName
, "#B7");
633 // Input string was not in a correct format
634 FormatException fe
= (FormatException
) ex
.InnerException
;
635 Assert
.IsNull (fe
.InnerException
, "#B8");
636 Assert
.IsNotNull (fe
.Message
, "#B9");
641 cn
.ConnectionString
= "timeout=2147483648";
643 } catch (ArgumentException ex
) {
644 // Invalid value for key 'connect timeout'
645 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#C2");
646 Assert
.IsNotNull (ex
.InnerException
, "#C3");
647 Assert
.AreEqual (typeof (OverflowException
), ex
.InnerException
.GetType (), "#C4");
648 Assert
.IsNotNull (ex
.Message
, "#C5");
649 Assert
.IsTrue (ex
.Message
.IndexOf ("'connect timeout'") != -1, "#C6:" + ex
.Message
);
650 Assert
.IsNull (ex
.ParamName
, "#C7");
652 // Value was either too large or too small for an Int32
653 OverflowException oe
= (OverflowException
) ex
.InnerException
;
654 Assert
.IsNull (oe
.InnerException
, "#C8");
655 Assert
.IsNotNull (oe
.Message
, "#C9");
660 #if FEATURE_NO_BSD_SOCKETS
661 [ExpectedException (typeof (PlatformNotSupportedException
))]
663 public void ConnectionString_Database_Synonyms ()
665 SqlConnection cn
= null;
667 cn
= new SqlConnection ();
668 cn
.ConnectionString
= "Initial Catalog=db";
669 Assert
.AreEqual ("db", cn
.Database
);
671 cn
= new SqlConnection ();
672 cn
.ConnectionString
= "Database=db";
673 Assert
.AreEqual ("db", cn
.Database
);
677 #if FEATURE_NO_BSD_SOCKETS
678 [ExpectedException (typeof (PlatformNotSupportedException
))]
680 public void ConnectionString_DataSource_Synonyms ()
682 SqlConnection cn
= null;
684 cn
= new SqlConnection ();
685 cn
.ConnectionString
= "Data Source=server";
686 Assert
.AreEqual ("server", cn
.DataSource
);
688 cn
= new SqlConnection ();
689 cn
.ConnectionString
= "addr=server";
690 Assert
.AreEqual ("server", cn
.DataSource
);
692 cn
= new SqlConnection ();
693 cn
.ConnectionString
= "address=server";
694 Assert
.AreEqual ("server", cn
.DataSource
);
696 cn
= new SqlConnection ();
697 cn
.ConnectionString
= "network address=server";
698 Assert
.AreEqual ("server", cn
.DataSource
);
700 cn
= new SqlConnection ();
701 cn
.ConnectionString
= "server=server";
702 Assert
.AreEqual ("server", cn
.DataSource
);
706 #if FEATURE_NO_BSD_SOCKETS
707 [ExpectedException (typeof (PlatformNotSupportedException
))]
709 public void ConnectionString_MaxPoolSize ()
711 SqlConnection cn
= new SqlConnection ();
712 cn
.ConnectionString
= "Max Pool Size=2147483647";
713 cn
.ConnectionString
= "Max Pool Size=1";
714 cn
.ConnectionString
= "Max Pool Size=500";
718 #if FEATURE_NO_BSD_SOCKETS
719 [ExpectedException (typeof (PlatformNotSupportedException
))]
721 public void ConnectionString_MaxPoolSize_Invalid ()
723 SqlConnection cn
= new SqlConnection ();
727 cn
.ConnectionString
= "Max Pool Size=-1";
729 } catch (ArgumentException ex
) {
730 // Invalid value for key 'max pool size'
731 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#A2");
732 Assert
.IsNull (ex
.InnerException
, "#A3");
733 Assert
.IsNotNull (ex
.Message
, "#A4");
734 Assert
.IsTrue (ex
.Message
.IndexOf ("'max pool size'") != -1, "#A5:" + ex
.Message
);
735 Assert
.IsNull (ex
.ParamName
, "#A6");
740 cn
.ConnectionString
= "max Pool size=BB";
742 } catch (ArgumentException ex
) {
743 // Invalid value for key 'max pool size'
744 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#B2");
745 Assert
.IsNotNull (ex
.InnerException
, "#B3");
746 Assert
.AreEqual (typeof (FormatException
), ex
.InnerException
.GetType (), "#B4");
747 Assert
.IsNotNull (ex
.Message
, "#B5");
748 Assert
.IsTrue (ex
.Message
.IndexOf ("'max pool size'") != -1, "#B6:" + ex
.Message
);
749 Assert
.IsNull (ex
.ParamName
, "#B7");
751 // Input string was not in a correct format
752 FormatException fe
= (FormatException
) ex
.InnerException
;
753 Assert
.IsNull (fe
.InnerException
, "#B8");
754 Assert
.IsNotNull (fe
.Message
, "#B9");
759 cn
.ConnectionString
= "max pool size=2147483648";
761 } catch (ArgumentException ex
) {
762 // Invalid value for key 'max pool size'
763 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#C2");
764 Assert
.IsNotNull (ex
.InnerException
, "#C3");
765 Assert
.AreEqual (typeof (OverflowException
), ex
.InnerException
.GetType (), "#C4");
766 Assert
.IsNotNull (ex
.Message
, "#C5");
767 Assert
.IsTrue (ex
.Message
.IndexOf ("'max pool size'") != -1, "#C6:" + ex
.Message
);
768 Assert
.IsNull (ex
.ParamName
, "#C7");
770 // Value was either too large or too small for an Int32
771 OverflowException oe
= (OverflowException
) ex
.InnerException
;
772 Assert
.IsNull (oe
.InnerException
, "#C8");
773 Assert
.IsNotNull (oe
.Message
, "#C9");
776 // less than minimum (1)
778 cn
.ConnectionString
= "Min Pool Size=0;Max Pool Size=0";
780 } catch (ArgumentException ex
) {
781 // Invalid value for key 'max pool size'
782 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#D2");
783 Assert
.IsNull (ex
.InnerException
, "#D3");
784 Assert
.IsNotNull (ex
.Message
, "#D4");
785 Assert
.IsTrue (ex
.Message
.IndexOf ("'max pool size'") != -1, "#D5:" + ex
.Message
);
786 Assert
.IsNull (ex
.ParamName
, "#D6");
789 // less than min pool size
791 cn
.ConnectionString
= "Min Pool Size=5;Max Pool Size=4";
793 } catch (ArgumentException ex
) {
794 // Invalid min or max pool size values, min
795 // pool size cannot be greater than the max
797 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#E2");
798 Assert
.IsNull (ex
.InnerException
, "#E3");
799 Assert
.IsNotNull (ex
.Message
, "#E4");
800 Assert
.IsNull (ex
.ParamName
, "#E5");
805 #if FEATURE_NO_BSD_SOCKETS
806 [ExpectedException (typeof (PlatformNotSupportedException
))]
808 public void ConnectionString_MinPoolSize ()
810 SqlConnection cn
= new SqlConnection ();
811 cn
.ConnectionString
= "min Pool size=0";
812 cn
.ConnectionString
= "Min Pool size=100";
813 cn
.ConnectionString
= "Min Pool Size=2147483647;Max Pool Size=2147483647";
817 #if FEATURE_NO_BSD_SOCKETS
818 [ExpectedException (typeof (PlatformNotSupportedException
))]
820 public void ConnectionString_MinPoolSize_Invalid ()
822 SqlConnection cn
= new SqlConnection ();
826 cn
.ConnectionString
= "Min Pool Size=-1";
828 } catch (ArgumentException ex
) {
829 // Invalid value for key 'min pool size'
830 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#A2");
831 Assert
.IsNull (ex
.InnerException
, "#A3");
832 Assert
.IsNotNull (ex
.Message
, "#A4");
833 Assert
.IsTrue (ex
.Message
.IndexOf ("'min pool size'") != -1, "#A5:" + ex
.Message
);
834 Assert
.IsNull (ex
.ParamName
, "#A6");
839 cn
.ConnectionString
= "min Pool size=BB";
841 } catch (ArgumentException ex
) {
842 // Invalid value for key 'min pool size'
843 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#B2");
844 Assert
.IsNotNull (ex
.InnerException
, "#B3");
845 Assert
.AreEqual (typeof (FormatException
), ex
.InnerException
.GetType (), "#B4");
846 Assert
.IsNotNull (ex
.Message
, "#B5");
847 Assert
.IsTrue (ex
.Message
.IndexOf ("'min pool size'") != -1, "#B6:" + ex
.Message
);
848 Assert
.IsNull (ex
.ParamName
, "#B7");
850 // Input string was not in a correct format
851 FormatException fe
= (FormatException
) ex
.InnerException
;
852 Assert
.IsNull (fe
.InnerException
, "#B8");
853 Assert
.IsNotNull (fe
.Message
, "#B9");
858 cn
.ConnectionString
= "min pool size=2147483648";
860 } catch (ArgumentException ex
) {
861 // Invalid value for key 'min pool size'
862 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#C2");
863 Assert
.IsNotNull (ex
.InnerException
, "#C3");
864 Assert
.AreEqual (typeof (OverflowException
), ex
.InnerException
.GetType (), "#C4");
865 Assert
.IsNotNull (ex
.Message
, "#C5");
866 Assert
.IsTrue (ex
.Message
.IndexOf ("'min pool size'") != -1, "#C6:" + ex
.Message
);
867 Assert
.IsNull (ex
.ParamName
, "#C7");
869 // Value was either too large or too small for an Int32
870 OverflowException oe
= (OverflowException
) ex
.InnerException
;
871 Assert
.IsNull (oe
.InnerException
, "#C8");
872 Assert
.IsNotNull (oe
.Message
, "#C9");
877 #if FEATURE_NO_BSD_SOCKETS
878 [ExpectedException (typeof (PlatformNotSupportedException
))]
880 public void ConnectionString_MultipleActiveResultSets ()
882 SqlConnection cn
= new SqlConnection ();
883 cn
.ConnectionString
= "MultipleActiveResultSets=true";
887 #if FEATURE_NO_BSD_SOCKETS
888 [ExpectedException (typeof (PlatformNotSupportedException
))]
890 public void ConnectionString_MultipleActiveResultSets_Invalid ()
892 SqlConnection cn
= new SqlConnection ();
894 cn
.ConnectionString
= "MultipleActiveResultSets=1";
896 } catch (ArgumentException ex
) {
897 // Invalid value for key 'multipleactiveresultsets'
898 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#2");
899 Assert
.IsNull (ex
.InnerException
, "#3");
900 Assert
.IsNotNull (ex
.Message
, "#4");
901 Assert
.IsTrue (ex
.Message
.IndexOf ("'multipleactiveresultsets'") != -1, "#5:" + ex
.Message
);
902 Assert
.IsNull (ex
.ParamName
, "#6");
907 #if FEATURE_NO_BSD_SOCKETS
908 [ExpectedException (typeof (PlatformNotSupportedException
))]
910 public void ConnectionString_NetworkLibrary_Synonyms ()
912 SqlConnection cn
= new SqlConnection ();
913 cn
.ConnectionString
= "Net=DBMSSOCN";
914 cn
.ConnectionString
= "Network=DBMSSOCN";
915 cn
.ConnectionString
= "Network library=DBMSSOCN";
919 #if FEATURE_NO_BSD_SOCKETS
920 [ExpectedException (typeof (PlatformNotSupportedException
))]
922 public void ConnectionString_PacketSize ()
924 SqlConnection cn
= new SqlConnection ();
925 cn
.ConnectionString
= "Packet Size=1024";
926 Assert
.AreEqual (1024, cn
.PacketSize
, "#1");
927 cn
.ConnectionString
= "packet SizE=533";
928 Assert
.AreEqual (533, cn
.PacketSize
, "#2");
929 cn
.ConnectionString
= "packet SizE=512";
930 Assert
.AreEqual (512, cn
.PacketSize
, "#3");
931 cn
.ConnectionString
= "packet SizE=32768";
932 Assert
.AreEqual (32768, cn
.PacketSize
, "#4");
933 cn
.ConnectionString
= "packet Size=";
934 Assert
.AreEqual (8000, cn
.PacketSize
, "#5");
938 #if FEATURE_NO_BSD_SOCKETS
939 [ExpectedException (typeof (PlatformNotSupportedException
))]
941 public void ConnectionString_PacketSize_Invalid ()
943 SqlConnection cn
= new SqlConnection ();
945 // invalid packet size (< minimum)
947 cn
.ConnectionString
= "Packet Size=511";
949 } catch (ArgumentException ex
) {
950 // Invalid 'Packet Size'. The value must be an
951 // integer >= 512 and <= 32768
952 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#A2");
953 Assert
.IsNull (ex
.InnerException
, "#A3");
954 Assert
.IsNotNull (ex
.Message
, "#A4");
955 Assert
.IsTrue (ex
.Message
.IndexOf ("'Packet Size'") != -1, "#A5:" + ex
.Message
);
956 Assert
.IsNull (ex
.ParamName
, "#A6");
959 // invalid packet size (> maximum)
961 cn
.ConnectionString
= "packet SIze=32769";
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 (), "#B2");
967 Assert
.IsNull (ex
.InnerException
, "#B3");
968 Assert
.IsNotNull (ex
.Message
, "#B4");
969 Assert
.IsTrue (ex
.Message
.IndexOf ("'Packet Size'") != -1, "#B5:" + ex
.Message
);
970 Assert
.IsNull (ex
.ParamName
, "#B6");
975 cn
.ConnectionString
= "packet SIze=2147483648";
977 } catch (ArgumentException ex
) {
978 // Invalid value for key 'packet size'
979 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#C2");
980 Assert
.IsNotNull (ex
.InnerException
, "#C3");
981 Assert
.AreEqual (typeof (OverflowException
), ex
.InnerException
.GetType (), "#C4");
982 Assert
.IsNotNull (ex
.Message
, "#C5");
983 Assert
.IsTrue (ex
.Message
.IndexOf ("'packet size'") != -1, "#C6:" + ex
.Message
);
984 Assert
.IsNull (ex
.ParamName
, "#C7");
986 // Value was either too large or too small for an Int32
987 OverflowException oe
= (OverflowException
) ex
.InnerException
;
988 Assert
.IsNull (oe
.InnerException
, "#C8");
989 Assert
.IsNotNull (oe
.Message
, "#C9");
994 #if FEATURE_NO_BSD_SOCKETS
995 [ExpectedException (typeof (PlatformNotSupportedException
))]
997 public void ConnectionString_Password_Synonyms ()
999 SqlConnection cn
= new SqlConnection ();
1000 cn
.ConnectionString
= "Password=scrambled";
1001 cn
.ConnectionString
= "Pwd=scrambled";
1005 #if FEATURE_NO_BSD_SOCKETS
1006 [ExpectedException (typeof (PlatformNotSupportedException
))]
1008 public void ConnectionString_PersistSecurityInfo_Synonyms ()
1010 SqlConnection cn
= new SqlConnection ();
1011 cn
.ConnectionString
= "Persist Security Info=true";
1012 cn
.ConnectionString
= "PersistSecurityInfo=true";
1016 #if FEATURE_NO_BSD_SOCKETS
1017 [ExpectedException (typeof (PlatformNotSupportedException
))]
1019 public void ConnectionString_UserID_Synonyms ()
1021 SqlConnection cn
= new SqlConnection ();
1022 cn
.ConnectionString
= "User Id=test";
1023 cn
.ConnectionString
= "User=test";
1024 cn
.ConnectionString
= "Uid=test";
1028 #if FEATURE_NO_BSD_SOCKETS
1029 [ExpectedException (typeof (PlatformNotSupportedException
))]
1031 public void ConnectionString_UserInstance ()
1033 SqlConnection cn
= new SqlConnection ();
1034 cn
.ConnectionString
= "User Instance=true";
1038 #if FEATURE_NO_BSD_SOCKETS
1039 [ExpectedException (typeof (PlatformNotSupportedException
))]
1041 public void ConnectionString_UserInstance_Invalid ()
1043 SqlConnection cn
= new SqlConnection ();
1045 cn
.ConnectionString
= "User Instance=1";
1047 } catch (ArgumentException ex
) {
1048 // Invalid value for key 'user instance'
1049 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#2");
1050 Assert
.IsNull (ex
.InnerException
, "#3");
1051 Assert
.IsNotNull (ex
.Message
, "#4");
1052 Assert
.IsTrue (ex
.Message
.IndexOf ("'user instance'") != -1, "#5:" + ex
.Message
);
1053 Assert
.IsNull (ex
.ParamName
, "#6");
1058 #if FEATURE_NO_BSD_SOCKETS
1059 [ExpectedException (typeof (PlatformNotSupportedException
))]
1061 public void ConnectionString_OtherKeywords ()
1063 SqlConnection cn
= new SqlConnection ();
1064 cn
.ConnectionString
= "Application Name=test";
1065 cn
.ConnectionString
= "App=test";
1066 cn
.ConnectionString
= "Connection Reset=true";
1067 cn
.ConnectionString
= "Current Language=test";
1068 cn
.ConnectionString
= "Language=test";
1069 cn
.ConnectionString
= "Encrypt=false";
1070 //cn.ConnectionString = "Encrypt=true";
1071 //cn.ConnectionString = "Enlist=false";
1072 cn
.ConnectionString
= "Enlist=true";
1073 cn
.ConnectionString
= "Integrated Security=true";
1074 cn
.ConnectionString
= "Trusted_connection=true";
1075 cn
.ConnectionString
= "Max Pool Size=10";
1076 cn
.ConnectionString
= "Min Pool Size=10";
1077 cn
.ConnectionString
= "Pooling=true";
1078 cn
.ConnectionString
= "attachdbfilename=dunno";
1079 cn
.ConnectionString
= "extended properties=dunno";
1080 cn
.ConnectionString
= "initial file name=dunno";
1084 #if FEATURE_NO_BSD_SOCKETS
1085 [ExpectedException (typeof (PlatformNotSupportedException
))]
1087 public void Open_ConnectionString_Empty ()
1089 SqlConnection cn
= new SqlConnection ();
1090 cn
.ConnectionString
= string.Empty
;
1095 } catch (InvalidOperationException ex
) {
1096 // The ConnectionString property has not been
1098 Assert
.AreEqual (typeof (InvalidOperationException
), ex
.GetType (), "#2");
1099 Assert
.IsNull (ex
.InnerException
, "#3");
1100 Assert
.IsNotNull (ex
.Message
, "#4");
1105 #if FEATURE_NO_BSD_SOCKETS
1106 [ExpectedException (typeof (PlatformNotSupportedException
))]
1108 public void Open_ConnectionString_Null ()
1110 SqlConnection cn
= new SqlConnection ();
1111 cn
.ConnectionString
= null;
1116 } catch (InvalidOperationException ex
) {
1117 // The ConnectionString property has not been
1119 Assert
.AreEqual (typeof (InvalidOperationException
), ex
.GetType (), "#2");
1120 Assert
.IsNull (ex
.InnerException
, "#3");
1121 Assert
.IsNotNull (ex
.Message
, "#4");
1126 #if FEATURE_NO_BSD_SOCKETS
1127 [ExpectedException (typeof (PlatformNotSupportedException
))]
1129 public void Open_ConnectionString_Whitespace ()
1131 SqlConnection cn
= new SqlConnection ();
1132 cn
.ConnectionString
= " ";
1137 } catch (InvalidOperationException ex
) {
1138 // The ConnectionString property has not been
1140 Assert
.AreEqual (typeof (InvalidOperationException
), ex
.GetType (), "#2");
1141 Assert
.IsNull (ex
.InnerException
, "#3");
1142 Assert
.IsNotNull (ex
.Message
, "#4");
1147 #if FEATURE_NO_BSD_SOCKETS
1148 [ExpectedException (typeof (PlatformNotSupportedException
))]
1150 public void ServerVersion_Connection_Closed ()
1152 SqlConnection cn
= new SqlConnection ();
1154 Assert
.Fail ("#A1:" + cn
.ServerVersion
);
1155 } catch (InvalidOperationException ex
) {
1156 // Invalid operation. The connection is closed
1157 Assert
.AreEqual (typeof (InvalidOperationException
), ex
.GetType (), "#A2");
1158 Assert
.IsNull (ex
.InnerException
, "#A3");
1159 Assert
.IsNotNull (ex
.Message
, "#A4");
1162 cn
= new SqlConnection ("server=SQLSRV; database=Mono;");
1164 Assert
.Fail ("#B1:" + cn
.ServerVersion
);
1165 } catch (InvalidOperationException ex
) {
1166 // Invalid operation. The connection is closed
1167 Assert
.AreEqual (typeof (InvalidOperationException
), ex
.GetType (), "#B2");
1168 Assert
.IsNull (ex
.InnerException
, "#B3");
1169 Assert
.IsNotNull (ex
.Message
, "#B4");