|
925 | 925 | try
|
926 | 926 | {
|
927 | 927 | string connectString =
|
928 |
| - "Data Source=(local);User ID=ab;Password=MyPassword;" + |
| 928 | + "Data Source=(local);Integrated Security=SSPI" + |
929 | 929 | "Initial Catalog=AdventureWorks";
|
930 | 930 |
|
931 | 931 | SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectString);
|
|
1477 | 1477 | </note>
|
1478 | 1478 | <!-- SqlConnectionStringBuilder_Remove -->
|
1479 | 1479 | <code language="c#">
|
1480 |
| - using System; |
1481 |
| - using System.Data; |
1482 | 1480 | using Microsoft.Data.SqlClient;
|
1483 |
| - |
| 1481 | + |
1484 | 1482 | class Program
|
1485 | 1483 | {
|
1486 | 1484 | static void Main()
|
1487 | 1485 | {
|
1488 | 1486 | try
|
1489 | 1487 | {
|
1490 | 1488 | string connectString =
|
1491 |
| - "Data Source=(local);User ID=ab;Password= a1Pass@@11;" + |
1492 |
| - "Initial Catalog=AdventureWorks"; |
1493 |
| - |
| 1489 | + "Data Source=(local);User ID=ab;"; |
| 1490 | + |
1494 | 1491 | SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectString);
|
1495 | 1492 | Console.WriteLine("Original: " + builder.ConnectionString);
|
1496 |
| - |
| 1493 | + |
1497 | 1494 | // Use the Remove method
|
1498 |
| - // in order to reset the user ID and password back to their |
1499 |
| - // default (empty string) values. |
| 1495 | + // in order to reset the user ID back to its |
| 1496 | + // default (empty string) value. |
1500 | 1497 | builder.Remove("User ID");
|
1501 |
| - builder.Remove("Password"); |
1502 |
| - |
| 1498 | + |
1503 | 1499 | // Turn on integrated security:
|
1504 | 1500 | builder.IntegratedSecurity = true;
|
1505 |
| - |
| 1501 | + |
| 1502 | + // Turn off encryption for local db |
| 1503 | + builder.Encrypt = false; |
| 1504 | + |
1506 | 1505 | Console.WriteLine("Modified: " + builder.ConnectionString);
|
1507 |
| - |
| 1506 | + |
1508 | 1507 | using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
|
1509 | 1508 | {
|
1510 | 1509 | connection.Open();
|
|
1516 | 1515 | {
|
1517 | 1516 | Console.WriteLine(ex.Message);
|
1518 | 1517 | }
|
1519 |
| - |
| 1518 | + |
1520 | 1519 | Console.WriteLine("Press any key to finish.");
|
1521 | 1520 | Console.ReadLine();
|
1522 | 1521 | }
|
|
1526 | 1525 | The example displays the following text in the console window:
|
1527 | 1526 | </para>
|
1528 | 1527 | <code>
|
1529 |
| - Original: Data Source=(local);Initial Catalog=AdventureWorks;User ID=ab;Password= a1Pass@@11 |
1530 |
| - Modified: Data Source=(local);Initial Catalog=AdventureWorks;Integrated Security=True Database=AdventureWorks |
| 1528 | + Original: Data Source=(local);User ID=ab; |
| 1529 | + Modified: Data Source=(local);Integrated Security=True; Encrypt=false |
| 1530 | + Database = master |
1531 | 1531 | </code>
|
1532 | 1532 | </example>
|
1533 | 1533 | <exception cref="T:System.ArgumentNullException">
|
|
0 commit comments