Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Network Interfaces, error: 25 - Connection string is not valid in Powershell

Tags:

sql

powershell

$SQLconnection = New-Object System.Data.SqlClient.SqlConnection
$SQLconnection.ConnectionString = "Server = MySQLservername\MSSQLSERVER; Database = "MYSQLDB"; Integrated Security = True"
$SQLconnection.open()

In MSSQL 2012, works. In MSSQL 2005, got SQL Network Interfaces, error: 25 - Connection string is not valid.

If use "Server = MySQLServername" only in connectionstring, works. I am sure the instance name is right. Is it a bug of SQL 2005?

like image 624
user1657661 Avatar asked Sep 09 '12 04:09

user1657661


2 Answers

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.

like image 171
CircaLucid Avatar answered Sep 17 '22 19:09

CircaLucid


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"
like image 29
L.Le Avatar answered Sep 20 '22 19:09

L.Le