Skip to content

Commit

Permalink
Remove more passwords + update samples (#2929)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheenamalhotra authored Oct 25, 2024
1 parent 641892c commit a947223
Showing 1 changed file with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@
try
{
string connectString =
"Data Source=(local);User ID=ab;Password=MyPassword;" +
"Data Source=(local);Integrated Security=SSPI" +
"Initial Catalog=AdventureWorks";

SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectString);
Expand Down Expand Up @@ -1477,34 +1477,33 @@
</note>
<!-- SqlConnectionStringBuilder_Remove -->
<code language="c#">
using System;
using System.Data;
using Microsoft.Data.SqlClient;

class Program
{
static void Main()
{
try
{
string connectString =
"Data Source=(local);User ID=ab;Password= a1Pass@@11;" +
"Initial Catalog=AdventureWorks";

"Data Source=(local);User ID=ab;";

SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectString);
Console.WriteLine("Original: " + builder.ConnectionString);

// Use the Remove method
// in order to reset the user ID and password back to their
// default (empty string) values.
// in order to reset the user ID back to its
// default (empty string) value.
builder.Remove("User ID");
builder.Remove("Password");


// Turn on integrated security:
builder.IntegratedSecurity = true;


// Turn off encryption for local db
builder.Encrypt = false;

Console.WriteLine("Modified: " + builder.ConnectionString);

using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
{
connection.Open();
Expand All @@ -1516,7 +1515,7 @@
{
Console.WriteLine(ex.Message);
}

Console.WriteLine("Press any key to finish.");
Console.ReadLine();
}
Expand All @@ -1526,8 +1525,9 @@
The example displays the following text in the console window:
</para>
<code>
Original: Data Source=(local);Initial Catalog=AdventureWorks;User ID=ab;Password= a1Pass@@11
Modified: Data Source=(local);Initial Catalog=AdventureWorks;Integrated Security=True Database=AdventureWorks
Original: Data Source=(local);User ID=ab;
Modified: Data Source=(local);Integrated Security=True; Encrypt=false
Database = master
</code>
</example>
<exception cref="T:System.ArgumentNullException">
Expand Down

0 comments on commit a947223

Please sign in to comment.