Improve samples by building them
- Dominant language
- C#
- Stars
- 989
- Forks
- 340
- Avg merge
- 4d 18h
- Merged PRs (30d)
- 69
Description
### Is your feature request related to a problem? Please describe.
None of the samples in the docs/samples folder are built or compiled, leading to potentially unusable samples
### Describe the solution you'd like
Add a project and solution to build these at least locally
One of the challenges is that most of the samples have this shape:
```c#
using System;
using System.Data;
//
using Microsoft.Data.SqlClient;
class Program
{
static void Main()
{
OpenSqlConnection();
Console.ReadLine();
}
private static void OpenSqlConnection()
{
string connectionString = GetConnectionString();
using (SqlConnection connection = new SqlConnection())
{
connection.ConnectionString = connectionString;
connection.Open();
Console.WriteLine("State: {0}", connection.State);
Console.WriteLine("ConnectionString: {0}",
connection.ConnectionString);
}
}
static private string GetConnectionString()
{
// To avoid storing the connection string in your code,
// you can retrieve it from a configuration file.
return "Data Source=MSSQL1;Initial Catalog=AdventureWorks;"
+ "Integrated Security=true;";
}
}
//
```
Which of course causes clashes as Program is in the Global namespace
A possible solution would be to add namespaces to sample:
```c#
using System;
using System.Data;
//
using Microsoft.Data.SqlClient;
namespace SqlConnection_ConnectionString;
class Program
{
static void Main()
{
OpenSqlConnection();
Console.ReadLine();
}
private static void OpenSqlConnection()
{
string connectionString = GetConnectionString();
using (SqlConnection connection = new SqlConnection())
{
connection.ConnectionString = connectionString;
connection.Open();
Console.WriteLine("State: {0}", connection.State);
Console.WriteLine("ConnectionString: {0}",
connection.ConnectionString);
}
}
static private string GetConnectionString()
{
// To avoid storing the connection string in your code,
// you can retrieve it from a configuration file.
return "Data Source=MSSQL1;Initial Catalog=AdventureWorks;"
+ "Integrated Security=true;";
}
}
//
```
### Additional context
let me know if you think this adds value and I can do it.
Contributor guide
Assessment
This issue has not been assessed yet.