Skip to content

Commit 674894b

Browse files
committed
Tighten up nullability
1 parent 50c4aa1 commit 674894b

File tree

2 files changed

+12
-30
lines changed

2 files changed

+12
-30
lines changed

MssqlMcp/MssqlMcp/SqlConnectionFactory.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,20 @@ public class SqlConnectionFactory : ISqlConnectionFactory
88
{
99
public async Task<SqlConnection> GetOpenConnectionAsync()
1010
{
11-
var connectionString = SqlConnectionManager.GetSqlConfig();
11+
var connectionString = GetConnectionString();
12+
13+
// Let ADO.Net handle connection pooling
1214
var conn = new SqlConnection(connectionString);
1315
await conn.OpenAsync();
1416
return conn;
1517
}
18+
19+
private static string GetConnectionString()
20+
{
21+
var connectionString = Environment.GetEnvironmentVariable("CONNECTION_STRING");
22+
23+
return string.IsNullOrEmpty(connectionString)
24+
? throw new InvalidOperationException("Connection string is not set in the environment variable 'CONNECTION_STRING'.\n\nHINT: Have a local SQL Server, with a database called 'test', from console, run `SET CONNECTION_STRING=Server=.;Database=test;Trusted_Connection=True;TrustServerCertificate=True` and the load the .sln file")
25+
: connectionString;
26+
}
1627
}

MssqlMcp/MssqlMcp/SqlConnectionManager.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)