12
$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?

1
  • I believe the term "Database" should be "Initial Catalog". Commented Sep 9, 2012 at 6:19

8 Answers 8

10

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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"

1 Comment

Would you please check whether my edit change the meaning of your post? Thanks.
1

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"

Comments

1

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"

Comments

1

Quoting problem

(This answer here builds on and contradicts the answer given by Chad earlier: SQL Network Interfaces, error: 25 - Connection string is not valid in Powershell)

You seem to have a quoting problem. In newer versions of the PowerShell console the syntax highlighting can help you see this.

See screenshot below: $a is wrong. $b and $c work. Syntax highlighting shows quoting problem

So version $a will not work. To work around this you must change your quoting. Either as in $b or in $c. I prefer $c.

Further reading: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules

Screenshot as Text

$a = "Server = MySQLservername\MSSQLSERVER; Database = "MYSQLDB"; Integrated Security = True"
At line:1 char:57
+ ... ername\MSSQLSERVER; Database = "MYSQLDB"; Integrated Security = True"
+                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token 'MYSQLDB"; Integrated Security = True"' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

$b = "Server = MySQLservername\MSSQLSERVER; Database = `"MYSQLDB`"; Integrated Security = True"
$c = 'Server = MySQLservername\MSSQLSERVER; Database = "MYSQLDB"; Integrated Security = True'

$a

$b
Server = MySQLservername\MSSQLSERVER; Database = "MYSQLDB"; Integrated Security = True

$c
Server = MySQLservername\MSSQLSERVER; Database = "MYSQLDB"; Integrated Security = True

Comments

0

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"

Comments

0

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://learn.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.

Comments

0

I encountered the "SQL Network Interfaces, error: 25 - Connection string is not valid" error while attempting to establish a connection using my credentials. I successfully resolved this issue by removing a semicolon from the server name in my connection string.

To provide further context, the error typically arises when there is an issue with the connection string, preventing the database client from establishing a valid connection to the server. In my case, the presence of a semicolon in the server name was causing the connection string to be improperly formatted.

By removing the semicolon, I ensured that the connection string adhered to the correct format, allowing the database client to establish a successful connection. If you encounter a similar error, I recommend carefully reviewing your connection string for any formatting issues that might be causing the problem.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.