Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System;
using Microsoft.Data.SqlClient;

namespace CustomAppIdAuthProviderExample
namespace ApplicationClientIdAzureAuthenticationProvider
{
public class Program
{
Expand Down
2 changes: 1 addition & 1 deletion doc/samples/AzureKeyVaultProviderExample_2_0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Microsoft.Data.SqlClient;
using Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider;

namespace Microsoft.Data.SqlClient.Samples
namespace AzureKeyVaultProviderExample_2_0
{
public class AzureKeyVaultProviderExample_2_0
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
/*
Copy link
Contributor Author

@ErikEJ ErikEJ Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excluded this from build, as it contains obsolete APIs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment to this effect?

Also, if you use #if false instead of the block comment /* */ then we still get nice IDE presentation and you can put comments about what isn't compiling adjacent to the offending lines.

using System;
//<Snippet1>
using System.Collections.Generic;
using System.Security.Cryptography;
Expand All @@ -7,7 +8,7 @@
using Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider;
using Microsoft.IdentityModel.Clients.ActiveDirectory;

namespace AKVEnclaveExample
namespace AzureKeyVaultProviderWithEnclaveProviderExample
{
class Program
{
Expand Down Expand Up @@ -264,3 +265,4 @@ public CustomerRecord(int id, string fName, string lName)
}
}
//</Snippet1>
*/
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Microsoft.Data.SqlClient;
using Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider;

namespace AKVEnclaveExample_2_0
namespace AzureKeyVaultProviderWithEnclaveProviderExample_2_0
{
class Program
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Microsoft.Data.SqlClient;
using Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider;

namespace AzureKeyVaultProviderExample
namespace AzureKeyVaultProvider_ColumnEncryptionKeyCacheScope
{
// <Snippet1>
class Program
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
namespace ConnectionStringSettings_RetrieveFromConfig;

using System;
// <Snippet1>
using System.Configuration;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
namespace ConnectionStringSettings_RetrieveFromConfigByName;

using System;
using System.Configuration;

class Program
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
namespace ConnectionStringSettings_RetrieveFromConfigByProvider;

using System;
using System.Data;
using Microsoft.Data.SqlClient;
using System.Configuration;
Expand Down
8 changes: 7 additions & 1 deletion doc/samples/ConnectionStringsWeb_Encrypt.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System;
/*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could not make this build, so commented out

#if NETFRAMEWORK
namespace ConnectionStringsWeb_Encrypt;

using System;
using System.Configuration;
using System.Web.Configuration;

Expand Down Expand Up @@ -35,3 +39,5 @@ static void ToggleWebEncrypt()
}
// </Snippet1>
}
#endif
*/
6 changes: 4 additions & 2 deletions doc/samples/ConnectionStrings_Encrypt.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
namespace ConnectionStrings_Encrypt;

using System;
using System.Configuration;

class Program
Expand All @@ -7,7 +9,7 @@ static void Main()
{
}
// <Snippet1>
static void ToggleConfigEncryption(string exeFile)
static void ToggleConfigEncryption(string exeConfigName)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected parameter name to make build pass

{
// Takes the executable file name without the
// .config extension.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Microsoft.Data.SqlClient;
using Microsoft.Identity.Client;

namespace CustomDeviceCodeFlowAuthProviderExample
namespace CustomDeviceCodeFlowAzureAuthenticationProviderExample
{
/// <summary>
/// Example demonstrating creating a custom device code flow authentication provider and attaching it to the driver.
Expand Down
2 changes: 2 additions & 0 deletions doc/samples/DataColumn_DataType.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
namespace DataColumn_DataType;

using System;
using System.Data;
// <Snippet1>
Expand Down
2 changes: 2 additions & 0 deletions doc/samples/DataTableReader_GetValues.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
namespace DataTableReader_GetValues;

// <Snippet1>
using System;
using System.Data;
Expand Down
2 changes: 1 addition & 1 deletion doc/samples/IBinarySerialize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Microsoft.SqlServer.Server;
using System.Text;

namespace test
namespace IBinarySerializeCS
{

public class Class1 : IBinarySerialize
Expand Down
4 changes: 4 additions & 0 deletions doc/samples/IDbCommand_CommandTimeout.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#if NETFRAMEWORK
namespace IDbCommand_CommandTimeout;

// <Snippet1>
using System;
using System.Xml;
Expand All @@ -20,3 +23,4 @@ public void CreateSqlCommand()
}
// </Snippet1>
}
#endif
2 changes: 2 additions & 0 deletions doc/samples/Isolation_Snapshot.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
namespace Isolation_Snapshot;

using System;
using System.Data;
// <Snippet1>
Expand Down
2 changes: 2 additions & 0 deletions doc/samples/Isolation_Snapshot1.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
namespace Isolation_Snapshot1;

using System;
using System.Data;
// <Snippet1>
Expand Down
4 changes: 3 additions & 1 deletion doc/samples/Microsoft.Data.SqlClient.Samples.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net462</TargetFrameworks>
Copy link
Contributor Author

@ErikEJ ErikEJ Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to make "dotnet build" work

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we target .NET 10 here instead of 8?

<OutputType>Library</OutputType>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand All @@ -16,10 +17,11 @@
<PackageReference Include="Microsoft.Data.SqlClient" />
<PackageReference Include="Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="System.Configuration.ConfigurationManager" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to make build pass

</ItemGroup>

<!-- .NET Framework references -->
<ItemGroup Condition="$(TargetGroup) == 'netfx'">
<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to make local "dotnet build" work

<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" />
<Reference Include="System.Transactions" />
<Reference Include="System.Windows.Forms" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.IO;
using Microsoft.SqlServer.Server;

namespace test
namespace DataWorks_IBinarySerialize_Sample
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we come up with a namespace convention for samples? For example, base namespace names of:

Microsoft.SqlServer.Server.Samples
Microsoft.Data.SqlClient.Samples

And then append something unique to make the complete namespace:

Microsoft.SqlServer.Server.Samples.DataWorks.IBinarySerialize

@benrr101 and others - should we discuss before Erik makes any changes here?

{
public class Class1 : IBinarySerialize
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.IO;
namespace DataWorks_SqlFunctionAttribute_Sample;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we prefer to put usings outside of any namespace declaration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to deliberate minimize impact on sample code - I think mentally this code base is quite different from production code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to deliberate minimize impact on sample code - I think mentally this code base is quite different from production code


using System.IO;
using System.Collections;
using Microsoft.SqlServer.Server;

Expand All @@ -20,4 +22,4 @@ public static IEnumerable GetFileDetails(string directoryPath)
}
}
//</Snippet1>
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//<Snippet1>
namespace DataWorks_SqlUserDefinedAggregateAttribute_Sample;

//<Snippet1>
using System;
using System.IO;
using Microsoft.SqlServer.Server;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
namespace DataWorks_SqlUserDefinedTypeAttribute_Sample;

using System;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Text;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections;
namespace SqlFunctionAttribute_SqlFunction;

using System.Collections;
//-----------------------------------------------------------------------------
//<Snippet4>
using System.Data.SqlTypes;
Expand Down
2 changes: 2 additions & 0 deletions doc/samples/Microsoft.SqlServer.Server/csharp/SqlMethod.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
namespace SqlMethodCSExample;

using System;
// <Snippet1>
using Microsoft.SqlServer.Server;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//-----------------------------------------------------------------------------
namespace SqlUserDefinedAggregateAttribute_Aggregate1;

//-----------------------------------------------------------------------------
//<Snippet2>
using System;
using System.Data.SqlTypes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//-----------------------------------------------------------------------------
namespace SqlUserDefinedTypeAttribute_Type1;

//-----------------------------------------------------------------------------
//<Snippet5>
using System;
using System.Data.SqlTypes;
Expand Down Expand Up @@ -78,8 +80,8 @@ public static Point Parse(SqlString s)
string[] xy = str.Split(':');

Point pt = new Point();
pt.X = Convert.Toint(xy[0]);
pt.Y = Convert.Toint(xy[1]);
pt.X = Convert.ToInt32(xy[0]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix of incorrect sample code

pt.Y = Convert.ToInt32(xy[1]);
return (pt);
}

Expand Down
27 changes: 24 additions & 3 deletions doc/samples/RegisterCustomKeyStoreProvider_CommandPrecedence.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
// <Snippet1>
namespace RegisterCustomKeyStoreProvider_CommandPrecedence;

using System.Collections.Generic;
using Azure.Identity;
using Microsoft.Data.SqlClient;
using Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider;

// <Snippet1>
class Program
{
static void Main()
static void Main(string connectionString)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added missing parameter to make build pass

{
Dictionary<string, SqlColumnEncryptionKeyStoreProvider> customKeyStoreProviders = new Dictionary<string, SqlColumnEncryptionKeyStoreProvider>();
MyCustomKeyStoreProvider firstProvider = new MyCustomKeyStoreProvider();
Expand All @@ -20,7 +27,7 @@ static void Main()
using (SqlCommand command = connection.CreateCommand())
{
customKeyStoreProviders.Clear();
SqlColumnEncryptionAzureKeyVaultProvider azureKeyVaultProvider = new SqlColumnEncryptionAzureKeyVaultProvider();
SqlColumnEncryptionAzureKeyVaultProvider azureKeyVaultProvider = new SqlColumnEncryptionAzureKeyVaultProvider(new DefaultAzureCredential());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uses the updated API to make build pass

customKeyStoreProviders.Add(SqlColumnEncryptionAzureKeyVaultProvider.ProviderName, azureKeyVaultProvider);
// Registers the provider on the command
// These providers will take precedence over connection-level providers and globally registered providers
Expand All @@ -30,3 +37,17 @@ static void Main()
}
}
// </Snippet1>

class MyCustomKeyStoreProvider : SqlColumnEncryptionKeyStoreProvider
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added dummy class to make build pass (not part of snippet)

{
public override byte[] DecryptColumnEncryptionKey(string masterKeyPath, string encryptionAlgorithm, byte[] encryptedColumnEncryptionKey)
{
// Custom decryption logic here
return new byte[0];
}
public override byte[] EncryptColumnEncryptionKey(string masterKeyPath, string encryptionAlgorithm, byte[] columnEncryptionKey)
{
// Custom encryption logic here
return new byte[0];
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
// <Snippet1>
namespace RegisterCustomKeyStoreProvider_ConnectionPrecedence;

using System.Collections.Generic;
using Azure.Core;
using Azure.Identity;
using Microsoft.Data.SqlClient;
using Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider;

// <Snippet1>
class Program
{
static void Main()
static void Main(string connectionString)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added missing parameter to make build pass

{
Dictionary<string, SqlColumnEncryptionKeyStoreProvider> customKeyStoreProviders = new Dictionary<string, SqlColumnEncryptionKeyStoreProvider>();
MyCustomKeyStoreProvider myProvider = new MyCustomKeyStoreProvider();
Expand All @@ -12,7 +20,7 @@ static void Main()
using (SqlConnection connection = new SqlConnection(connectionString))
{
customKeyStoreProviders.Clear();
SqlColumnEncryptionAzureKeyVaultProvider azureKeyVaultProvider = new SqlColumnEncryptionAzureKeyVaultProvider();
SqlColumnEncryptionAzureKeyVaultProvider azureKeyVaultProvider = new SqlColumnEncryptionAzureKeyVaultProvider(new DefaultAzureCredential());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the updated API to make build pass

customKeyStoreProviders.Add(SqlColumnEncryptionAzureKeyVaultProvider.ProviderName, azureKeyVaultProvider);
// Registers the provider on the connection
// These providers will take precedence over globally registered providers
Expand All @@ -21,3 +29,17 @@ static void Main()
}
}
// </Snippet1>

class MyCustomKeyStoreProvider : SqlColumnEncryptionKeyStoreProvider
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added dummy class to make build pass (not part of snippet)

{
public override byte[] DecryptColumnEncryptionKey(string masterKeyPath, string encryptionAlgorithm, byte[] encryptedColumnEncryptionKey)
{
// Custom decryption logic here
return new byte[0];
}
public override byte[] EncryptColumnEncryptionKey(string masterKeyPath, string encryptionAlgorithm, byte[] columnEncryptionKey)
{
// Custom encryption logic here
return new byte[0];
}
}
9 changes: 6 additions & 3 deletions doc/samples/RegisterCustomKeyStoreProvider_Example.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// <Snippet1>
namespace RegisterCustomKeyStoreProvider_Example;

// <Snippet1>
using Azure.Identity;
using Microsoft.Data.SqlClient;
using Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider;
using System.Collections.Generic;
Expand All @@ -15,7 +18,7 @@ void ExecuteSelectQuery(object user, SqlConnection connection)
if (azureKeyVaultProvider is null)
{
// Create a new SqlColumnEncryptionAzureKeyVaultProvider with the user's credentials and save it for future use
azureKeyVaultProvider = new SqlColumnEncryptionAzureKeyVaultProvider();
azureKeyVaultProvider = new SqlColumnEncryptionAzureKeyVaultProvider(new DefaultAzureCredential());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the updated API to make build pass

providerByUser[user] = azureKeyVaultProvider;
}

Expand All @@ -35,7 +38,7 @@ void ExecuteUpdateQuery(object user, SqlConnection connection)
if (azureKeyVaultProvider is null)
{
// Create a new SqlColumnEncryptionAzureKeyVaultProvider with the user's credentials and save it for future use
azureKeyVaultProvider = new SqlColumnEncryptionAzureKeyVaultProvider();
azureKeyVaultProvider = new SqlColumnEncryptionAzureKeyVaultProvider(new DefaultAzureCredential());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the updated API to make build pass

providerByUser[user] = azureKeyVaultProvider;
}

Expand Down
Loading
Loading