$SQLconnection = New-Object System.Data.SqlClient.SqlConnection
$SQLconnection.ConnectionString = \"Server = MySQLservername\\MSSQLSERVER; Database = \"MYSQLDB\"; In
Per MS, you can't connect to the default instance, MSSQLSERVER, by name. You have to omit the instance name. I've verified this same "feature" in MS SQL 2008R2 and 2014 SP2.
There might be something that you configured in 2012 that enabled it, but my default setups don't work with it.
You're constructing your string incorrectly and I'm surprised this works at all for any version. You have "MYSQLDB" in the middle of the connection string and you didn't escape the double quotes in the quoted string. You can see this by running these two commands:
$a = write-output "Server = MySQLservername\MSSQLSERVER; Database = "MYSQLDB"; Integrated Security = True"
$b = write-output "Server = MySQLservername\MSSQLSERVER; Database = `"MYSQLDB`"; Integrated Security = True"
$a.gettype()
$b.gettype()
The first line returns an array instead of a string because the semi-colon is seen as running two commands
Just remember to escape double quotes in double-quoted strings you'll be fine:
$SQLconnection.ConnectionString = "Server = MySQLservername\MSSQLSERVER; Database = `"MYSQLDB`"; Integrated Security = True"
If your database/instance is provided on a port number, I got the error 25 when I didn't set up the connection string correctly.
$SQLconnection.ConnectionString = "Server = MySQLservername.domain.ext\InstanceName, PORT; Database = `"MYSQLDB`"; Integrated Security = True"
For example:
$SQLconnection.ConnectionString = "Server = SQL01v.fordco.prd\DBSYS, 1433; Database = CarsDB; Integrated Security = True"
I had the same error and changed appsettings.json to
"DefaultConnection": "Server=localhost; database=my-vue-starter-new;MultipleActiveResultSets=true;User Id=SA;Password=myPassword;"
important on linux the server is localhost and the Id automatically became SA
for more info: https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-ubuntu?view=sql-server-ver15
another thing may cause to gthat issue if you didn't configure mssql, enabled the tcpport to 1433 if not do it and try to connect again.
As far as I am aware, it has never been a requirement to quote the server or databasename in a connection string. You should be using this
$SQLconnection.ConnectionString = "Server=MySQLservername\MSSQLSERVER;Database=MYSQLDB;Integrated Security=True"
One way you will get this error is if you have your Network Profile
is set to "Public"
.
It needs to be "Private"
.
To change (or check).
Click Start->Settings->Network & Internet
Click Status
Click Change connection properties
Under Network Profile select "Private"