Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to pass a standard ado connection string to Invoke-SqlCmd

Is it possible to use a connection string like:

Data Source=[server];Initial Catalog=[database];Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False

or:

"Provider=SQLOLEDB.1;Persist Security Info=True;Initial Catalog=[database];Data Source=[server];uid=[username];pwd=[password];Pooling=true;Min Pool Size=10;Max Pool Size=500;Incr Pool Size=5;MultipleActiveResultSets=true;"

with Invoke-Sqlcmd?

like image 969
Jonas Røineslien Avatar asked Sep 10 '15 08:09

Jonas Røineslien


2 Answers

At the time this question was asked, no. More recently, yes, Invoke-Sqlcmd now supports a -ConnectionString parameter that accepts a standard database connection string as a value.

Previously, you'd need to break out each of the parameters in your connection string and match them up with the parameters that Invoke-Sqlcmd accepts.

If you had the flexibility and are stuck with a frozen legacy environment, you may wish to bodge Chad Miller's Invoke Sqlcmd2 and make it accept an ADO.NET connection string as one of its parameters:

https://gallery.technet.microsoft.com/scriptcenter/7985b7ef-ed89-4dfd-b02a-433cc4e30894

like image 185
Kev Avatar answered Oct 05 '22 12:10

Kev


Actually, Yes.

As of this writing the invoke-sqlcmd available in the SQLServer module includes a -connectionString parameter.

like image 45
Jthorpe Avatar answered Oct 05 '22 12:10

Jthorpe