I am just trying to establish a connection with the SQL Server.
The situation is that PowerShell is running on my machine and there is no instance of the sever on my machine. This SQL Server is on another server, Server9. If I have to look at the tables I use SQL Server Management Studio to look at the data and run some queries.
The authentication is set to SQL Server and Windows authentication mode. I checked the server properties under Connections the option of Allow remote connections to this server is ticked. I am guessing the server is set up for remote connection.
Additional info: I downloaded the SQL Server and SQLPS modules. Running PowerShell 5.1 on PowerShell ISE
Connection code is:
$sqlConn = New-Object System.Data.SqlClient.SqlConnection
$sqlConn.ConnectionString = “Server=MSSQLSERVER;database=Server9;Integrated Security=true;Initial Catalog=master;Trusted_Connection=True”
$sqlConn.Open()
Error message:
Exception calling "Open" with "0" argument(s): "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
At line:3 char:1
- $sqlConn.Open()
- CategoryInfo : NotSpecified: (:) [], MethodInvocationException
- FullyQualifiedErrorId : SqlException
MSSQLSERVER? If so can you ping it? Have you enabled TCP and Remote Connections? Is it a named instance or a default instance of SQL Server? If the latter is SQL Server Browser running? Have you made a firewall exception for it?Test-Connection, no issues there. Complete server name isserver9.server.nii. I used this name in the connection string too but it doesn't work. If there are any settings that I can check from MS SQL Sever Management please let me know.MSSQLSERVERcome in? Is it a named instance with that name? More likely it is a default instance, as default instances usually use that name. Therefore your connection string should probably beServer=server9.server.nii;Integrated Security=true;Initial Catalog=master;Trusted_Connection=Truenote thatInitial Cataloganddatabaseare the same thing. If it is a named instance then you need to change it toServer=server9.server.nii\MSSQLSERVER...