PowerShell: network-related or instance-specific error occurred while establishing a connection to SQL Server - sql

On my Skype For Business Server, when I run the following command, my Queue get's changed as it should:
Set-CsRgsQueue -Instance $queue
On my linked server however (one hop away from the Lync server), i get the following error:
network-related or instance-specific error occurred while
establishing a connection to SQL Server. Set-CsRgsQueue : 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
I am however able to set up ODBC to the remote server (+ opened FW 1433 port, restarted the service ,....)
Where could my problem be?
EDIT:
My scriptblock looks like:
import-module Lync
$queue = Get-CsRgsQueue -Name $toChange
$action = New-CsRgsCallAction -Action TransferToPSTN -Uri $forwarduri -QueueID $queue.Identity
$queue.OverflowAction = $action
$queue.OverflowThreshold = 0
Set-CsRgsQueue -Instance $queue
If i'm not able to solve the issue, how could I implement invoke-command as this works on the server itself?
I tried by doing:
Invoke-Command -ComputerName SQLSERVER -ScriptBlock {Set-CsRgsQueue -Instance $queue}
but this throws:
Cannot validate argument on parameter 'Instance'. The argument is null. Provide a valid value for the argument, and then try running the command again.

Related

Connection String Error (error : 40)

I have installed SQL Server 2012 Express on a Windows Server 2008 Machine. The name of the machine is "THEMACHINE". While installation, I set SQL Server 2012 as "Default Instance".
Now I set my connection string like this :
<add name="BooksContext" providerName="System.Data.SqlClient" connectionString="Data Source=THEMACHINE;Initial Catalog=newdb; User ID=sa; Password=123456"/>
But I get this exception :
{"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)"}
I checked that database is running. Can you tell me what I'm doing wrong?Thanks.
Reference: Creating and Configuring Universal Data Link (.udl) Files
Do following to Test connection and generate connection string,
1) Create query.udl file in the desktop
2) Double click the file to open and do the following
3)Open the Query.udl in notepad, you will find the connectionstring.
Change Data Source=THEMACHINE to Data Source=THEMACHINE\SQLEXPRESS. Also check that the database service is running.

Cannot connect to localdb in Visual Studio

I keep getting this error when I try to do an update-database command in the package manager console:
ClientConnectionId:00000000-0000-0000-0000-000000000000
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: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Specified LocalDB instance name is invalid.
)
My connection string is:
<connectionStrings>
<add name="BookServiceContext" connectionString="Data Source=(localdb)\\v11.0; Initial Catalog=BookServiceContext-20150228232739; Integrated Security=True; MultipleActiveResultSets=True; AttachDbFilename=|DataDirectory|BookServiceContext-20150228232739.mdf" providerName="System.Data.SqlClient" />
</connectionStrings>
I can connect via SSMS 2014 and I can see (localdb)\MSSQLLocalDB and (localdb)\ProjectsV12 in the SQL Server Object Explorer.
EDIT
Even when a part of connection string is changed to:
AttachDbFilename=|DataDirectory|\BookServiceContext-20150228232739.mdf"
It still pulls the same error.
There is a backslash missing in you connection string:
instead of
AttachDbFilename=|DataDirectory|BookServiceContext-20150228232739.mdf"
it should be
AttachDbFilename=|DataDirectory|\BookServiceContext-20150228232739.mdf"
Refer to Creating a Connection String and Working with SQL Server LocalDB
Update
It turns out that after a \ wasn't missing but there are too many of them. I was able to reproduce the error by adding another \ to
Data Source=(localdb)\\v11.0
this means your Data Source should be:
Data Source=(localdb)\v11.0
with only one \
Kindly check your connection string
Data Source=(localdb)\ProjectsV13;Initial Catalog=master;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False

Creating bcp format file from local database table - connection error

I need to create a format file from a local database table but I get a connection error when I try to run the command in cmd. Here is the command I am using:
bcp OrderDatabase.dbo.Orders format nul -c -f D:\Format\Orders.fmt -T
I get the following errors:
SQLState = 08001, NativeError = 2
Error = [Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [2].
SQLState = 08001, NativeError = 2
Error = [Microsoft][SQL Server Native Client 11.0]A network-related or instance-
specific error has occurred while establishing a connection to SQL Server.
Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.
SQLState = S1T00, NativeError = 0
Error = [Microsoft][SQL Server Native Client 11.0]Login timeout expired
I have checked Services.msc and SQL Server is indeed "Started". I have also checked Sql Server Configuration Manager and the SQL Server state is "Running" and Start Mode is "Automatic".
The connection string to the local database is:
Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\Tools_TextileMagazine\CSharp_Template\Tools_TextileMagazine\OrderDatabase.mdf;Integrated Security=True
Any ideas to what could be wrong?
Add the -S parameter like specified here:
http://msdn.microsoft.com/it-it/library/ms162802.aspx
So your connection string will be:
bcp OrderDatabase.dbo.Orders format nul -c -f D:\Format\Orders.fmt -T -S localhost\V11.0
I assume from your connection string that you named istance: V11.0

Connection string for SQL Server

I have connection string, but it isn't working. Why?
Error:
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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Connection string:
<add name="CompanyEventConnectionString"
connectionString="database=db;server=PETLITSKY-R\SQLEXP;user id=sas; password=P#ssword1; MultipleActiveResultSets=True;" />
In the SQL Server Configuration Manager->SQL Server Network Configuration->Protocols, check that named pipes and tcp/ip are enabled.
If that doesn't work then it may be your firewall blocking it, try this link: http://msdn.microsoft.com/en-us/library/cc646023.aspx
This may be useful too: http://support.microsoft.com/kb/287932
<add name="ConString" connectionString="Data Source=.;InitialCatalog=ServerMaintenance;User Id=sa;Password=something;" />

Getting Error with an SQL query

I'm getting an error when running this query in SQL Server 2008:
EXEC master..xp_cmdshell'bcp
"select Row_ID, Service_Code,Skill from Account_Service"
queryout "d:\text.txt" -c -T -x'
Error is:
SQLState = 08001, NativeError = 2
Error = [Microsoft][SQL Server Native Client 10.0]Named Pipes Provider: Could not open a connection to SQL Server [2].
SQLState = 08001, NativeError = 2
Error = [Microsoft][SQL Server Native Client 10.0]A network-related or instance-specific error has occurred while
establishing a connection to SQL Server. Server is not found or not
accessible. Check if instance name is correct and if SQL Server is
configured to allow remote connections. For more information see
SQL Server Books Online.
SQLState = S1T00, NativeError = 0
Error = [Microsoft][SQL Server Native Client 10.0]
Login timeout expired
NOTE: Shared Memory, Named Pipes, TCP/IP are all enabled in SQL Server Configuration Manager
Look into the SQL Configuration Manager.
I guess TCP/IP Protocoll is not enabled, so you can Access your SQL Server via. Shared Memory.
So you would be able to Connect if you are on the SQL Server it self but can not Access it from another Maschine.
Otherwise I would say it is an Network Problem as you see the Connection times out. Maybe a Firewall Software is blocking or your Server can not be reached.
The most likely Cause I expririenced, fitting to oyur discrition is disabled TCP/IP Protocol for SQL Server.