Skip to content

Commit 970923b

Browse files
committed
#108: params for MS SQL Server
1 parent ec17328 commit 970923b

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

.github/workflows/dub.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,4 @@ jobs:
223223
env:
224224
PORT: ${{ job.services.mssql.ports[1433] }}
225225
run: |
226-
./ddbctest --connection=odbc://127.0.0.1:$PORT --user=SA --password=MSbbk4k77JKH88g54 --driver="ODBC Driver 18 for SQL Server" --trusted_connection=yes
226+
./ddbctest --connection=odbc://127.0.0.1:$PORT --user=SA --password=MSbbk4k77JKH88g54 --driver="ODBC Driver 18 for SQL Server" --trust_server_certificate=yes

example/source/testddbc.d

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct ConnectionParams
8282
string host;
8383
ushort port;
8484
string database;
85-
string trusted_connection; // for MS-SQL can be setto 'yes'
85+
string trust_server_certificate; // for MS-SQL can be set to 'yes'
8686
}
8787
int main(string[] args)
8888
{
@@ -102,7 +102,7 @@ int main(string[] args)
102102
{
103103
getopt(args, "user",&par.user, "password",&par.password, "ssl",&par.ssl,
104104
"connection",&URI, "database",&par.database, "driver",&par.odbcdriver,
105-
"trusted_connection",&par.trusted_connection);
105+
"trust_server_certificate",&par.trust_server_certificate);
106106
}
107107
catch (GetOptException)
108108
{
@@ -207,7 +207,7 @@ int main(string[] args)
207207
// ./ddbctest --connection=ddbc:odbc://localhost --user=SA --password=bbk4k77JKH88g54 --driver=FreeTDS
208208
params = ODBCDriver.setUserAndPassword(par.user, par.password);
209209
params["driver"] = par.odbcdriver;
210-
params["trusted_connection"] = par.trusted_connection;
210+
params["trust_server_certificate"] = par.trust_server_certificate;
211211
url = ODBCDriver.generateUrl(par.host, par.port, params);
212212
}
213213
}

source/ddbc/drivers/odbcddbc.d

+17-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,23 @@ version (USE_ODBC)
424424
addToConnectionString("username", "Uid");
425425
addToConnectionString("password", "Pwd");
426426
addToConnectionString("database", "Database");
427-
addToConnectionString("trusted_connection", "TrustServerCertificate");
427+
addToConnectionString("encrypt", "Encrypt"); // defaults to no
428+
addToConnectionString("trusted_connection", "Trusted_Connection");
429+
addToConnectionString("trust_server_certificate", "TrustServerCertificate"); // Yes|No
430+
431+
// other potential params:
432+
// addToConnectionString("", "Provider"); // SQLNCLI10 or SQLNCLI11
433+
// addToConnectionString("", "Data Source");
434+
// addToConnectionString("", "Network Library"); // DBMSSOCN
435+
// addToConnectionString("", "Initial Catalog");
436+
// addToConnectionString("", "Integrated Security"); // true|false|SSPI
437+
// addToConnectionString("", "Asynchronous Processing"); // True|False
438+
// addToConnectionString("", "AttachDbFilename");
439+
// addToConnectionString("", "Failover Partner");
440+
// addToConnectionString("", "Column Encryption Setting"); // enabled;
441+
// addToConnectionString("", "Enclave Attestation Url");
442+
// addToConnectionString("", "MultipleActiveResultSets"); // true;
443+
// addToConnectionString("", "Packet Size"); // 4096; (default is 8192)
428444
string connectionString = connectionProps.join(';');
429445

430446
info(connectionString);

test/ddbctest/odbctest.d

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ version(USE_ODBC) {
2626
// "ODBC Driver 18 for SQL Server"
2727
// "FreeTDS"
2828
super(
29-
"odbc://localhost,%s?user=SA,password=MSbbk4k77JKH88g54,trusted_connection=yes,driver=ODBC Driver 18 for SQL Server".format(environment.get("MSSQL_PORT", "1433")), // don't specify database!
29+
"odbc://localhost,%s?user=SA,password=MSbbk4k77JKH88g54,trust_server_certificate=yes,driver=ODBC Driver 18 for SQL Server".format(environment.get("MSSQL_PORT", "1433")), // don't specify database!
3030
"DROP TABLE IF EXISTS [my_first_test];CREATE TABLE [my_first_test] ([id] INT NOT NULL IDENTITY(1,1) PRIMARY KEY, [name] VARCHAR(255) NOT NULL)",
3131
"DROP TABLE IF EXISTS [my_first_test]"
3232
);
@@ -64,7 +64,7 @@ version(USE_ODBC) {
6464

6565
this() {
6666
super(
67-
"odbc://localhost,%s?user=SA,password=MSbbk4k77JKH88g54,trusted_connection=yes,driver=ODBC Driver 18 for SQL Server".format(environment.get("MSSQL_PORT", "1433")), // don't specify database!
67+
"odbc://localhost,%s?user=SA,password=MSbbk4k77JKH88g54,trust_server_certificate=yes,driver=ODBC Driver 18 for SQL Server".format(environment.get("MSSQL_PORT", "1433")), // don't specify database!
6868
"CREATE TABLE records (id INT IDENTITY(1, 1) PRIMARY KEY, name VARCHAR(255) NOT NULL)",
6969
"DROP TABLE IF EXISTS records"
7070
);

0 commit comments

Comments
 (0)