Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added -D option to allow for old style connection strings #50

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Options:
-p, --pass <pass> Password to use for authentication
-o, --port <port> Port to connect to
-t, --timeout <timeout> Connection timeout in ms
-D, --dsn <old style dsn> Classic DSN connection string
-d, --database <database> Database to connect to
-q, --query <query> The query to execute
-v, --tdsVersion <tdsVersion> Version of tds protocol to use [7_4, 7_2, 7_3_A, 7_3_B, 7_4]
Expand All @@ -48,6 +49,13 @@ To connect to a SQL Server instance in Azure invoke mssql as follows
mssql -s abcdef.database.windows.net -u username@abcdef -p thepassword -d mydatabase -e
```

A classic style DSN connection string may be used in lieu of all other
options

``` bash
mssql -D "Server=localhost,1433;UID=DOMAIN\\user;PWD=password"
```

You will get a prompt as follows:
```bash
Connecting to abcdef.database.windows.net...done
Expand Down
10 changes: 7 additions & 3 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
.option('-o, --port <port>', 'Port to connect to')
.option('-t, --timeout <timeout>', 'Connection timeout in ms')
.option('-T, --requestTimeout <timeout>', 'Request timeout in ms')
.option('-D, --dsn <old-style dsn>', 'DSN connection string')
.option('-d, --database <database>', 'Database to connect to')
.option('-q, --query <query>', 'The query to execute')
.option('-v, --tdsVersion <tdsVersion>', 'Version of tds protocol to use [7_4, 7_2, 7_3_A, 7_3_B, 7_4]')
Expand All @@ -39,7 +40,7 @@
this.env = env;
this.args = {};
_.extend(this.args, _.pick(program, 'server', 'user', 'pass',
'port', 'requestTimeout', 'timeout',
'port', 'requestTimeout', 'timeout', 'dsn',
'database', 'query', 'tdsVersion',
'encrypt', 'format', 'config'));

Expand Down Expand Up @@ -74,6 +75,7 @@
user: env.SQLCLI_USER || 'sa',
pass: env.SQLCLI_PASSWORD,
server: env.SQLCLI_SERVER || 'localhost',
dsn: env.SQLCLI_DSN,
database: env.SQLCLI_DATABASE,
port: env.SQLCLI_PORT,
timeout: env.SQLCLI_TIMEOUT,
Expand All @@ -84,7 +86,8 @@

config = _.extend({}, defaults, config, args);

var connectInfo = {
var connectInfo = !config.dsn
? {
user: config.user,
password: config.pass,
server: config.server,
Expand All @@ -100,7 +103,8 @@
max: 1,
min: 1
}
};
}
: config.dsn ;

return connectInfo;
}
Expand Down