Skip to content

Commit 28665f7

Browse files
committed
Use 'await using' in various doc examples
Signed-off-by: Jesper Noordsij <jesper.noordsij@gmail.com>
1 parent 9db104f commit 28665f7

File tree

12 files changed

+32
-33
lines changed

12 files changed

+32
-33
lines changed

docs/content/api/MySqlConnector/MySqlBatchType.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/content/api/MySqlConnector/MySqlBulkCopyType.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/content/api/MySqlConnector/MySqlBulkLoaderType.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/content/diagnostics/logging.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,16 @@ var loggerFactory = LoggerFactory.Create(builder =>
101101
);
102102

103103
// now create a MySqlDataSource and configure it with the LoggerFactory
104-
using var dataSource = new MySqlDataSourceBuilder(yourConnectionString)
104+
await using var dataSource = new MySqlDataSourceBuilder(yourConnectionString)
105105
.UseLoggerFactory(loggerFactory)
106106
.Build();
107107

108108
// create all MySqlConnection objects via the MySqlDataSource, not directly
109-
// DON'T: using var connection = new MySqlConnection(yourConnectionString);
110-
using var connection = dataSource.CreateConnection();
109+
// DON'T: await using var connection = new MySqlConnection(yourConnectionString);
110+
await using var connection = dataSource.CreateConnection();
111111

112112
// you can also create open connections
113-
using var connection = await dataSource.OpenConnectionAsync();
113+
await using var connection = await dataSource.OpenConnectionAsync();
114114
```
115115

116116
### Deprecated Logging Framework

docs/content/diagnostics/metrics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ A connection pool name can be specified by one of the following means:
5959
The `MySqlDataSourceBuilder.UseName` method can be used to specify a name for the connection pool:
6060

6161
```csharp
62-
using var dataSource = new MySqlDataSourceBuilder("...connection string...")
62+
await using var dataSource = new MySqlDataSourceBuilder("...connection string...")
6363
.UseName("MyPoolName")
6464
.Build();
6565
```
@@ -86,7 +86,7 @@ builder.Services.AddKeyedMySqlDataSource("MyPoolName",
8686
Finally, the connection pool name can be specified by setting the `Application Name` connection string option:
8787

8888
```csharp
89-
using var connection = new MySqlConnection("server=dbserver;...;Application Name=MyPoolName");
89+
await using var connection = new MySqlConnection("server=dbserver;...;Application Name=MyPoolName");
9090
```
9191

9292
If `UseName` is used, it will override the `Application Name` connection string option.

docs/content/home.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ MySqlConnector also fully supports asynchronous I/O. The C# example above can be
4848
await using var connection = new MySqlConnection("Server=myserver;User ID=mylogin;Password=mypass;Database=mydatabase");
4949
await connection.OpenAsync();
5050

51-
using var command = new MySqlCommand("SELECT field FROM table;", connection);
51+
await using var command = new MySqlCommand("SELECT field FROM table;", connection);
5252
await using var reader = await command.ExecuteReaderAsync();
5353
while (await reader.ReadAsync())
5454
Console.WriteLine(reader.GetString(0));

docs/content/troubleshooting/connection-reuse.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ an open `MySqlDataReader`.
2222
You may not execute multiple operations in parallel, for example:
2323

2424
```csharp
25-
using var connection = new MySqlConnection("...");
25+
await using var connection = new MySqlConnection("...");
2626
await connection.OpenAsync();
2727
await Task.WhenAll( // don't do this
2828
connection.ExecuteAsync("SELECT 1;"),

docs/content/tutorials/basic-api.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ using (var cmd = new MySqlCommand())
3030
}
3131

3232
// Retrieve all rows
33-
using var command = new MySqlCommand("SELECT some_field FROM data", connection);
34-
using var reader = await cmd.ExecuteReaderAsync();
33+
await using var command = new MySqlCommand("SELECT some_field FROM data", connection);
34+
await using var reader = await cmd.ExecuteReaderAsync();
3535
while (await reader.ReadAsync())
3636
Console.WriteLine(reader.GetString(0));
3737
```
3838

3939
You can find more info about the ADO.NET API in the [MSDN documentation](https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/ado-net-overview) or in many tutorials on the Internet.
40-

docs/content/tutorials/best-practices.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public class Controllers
159159
{
160160
using var db = new AppDb();
161161
await db.Connection.OpenAsync();
162-
using var cmd = db.Connection.CreateCommand();
162+
await using var cmd = db.Connection.CreateCommand();
163163
cmd.CommandText = @"SELECT SLEEP(1)";
164164
await cmd.ExecuteNonQueryAsync();
165165
}

docs/content/tutorials/connect-to-mysql.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,16 @@ In ASP.NET Core, the `MySqlConnection` object will be dependency-injected into y
7272
other kinds of projects, you may need to explicitly create the connection:
7373

7474
```csharp
75-
using var connection = new MySqlConnection(yourConnectionString);
75+
await using var connection = new MySqlConnection(yourConnectionString);
7676
```
7777

7878
You can then open the connection and execute a query:
7979

8080
```csharp
8181
await connection.OpenAsync();
8282

83-
using var command = new MySqlCommand("SELECT field FROM table;", connection);
84-
using var reader = await command.ExecuteReaderAsync();
83+
await using var command = new MySqlCommand("SELECT field FROM table;", connection);
84+
await using var reader = await command.ExecuteReaderAsync();
8585
while (await reader.ReadAsync())
8686
{
8787
var value = reader.GetValue(0);

0 commit comments

Comments
 (0)