C# - Named Pipes Provider, Error: 40 - local access - c#

I developed a windows application on another system, SQL Server was located somewhere on another server, standard instance, data access was not a problem at all.
Now I have to do some work on the application on my own system, where I have a Standard SQL Server on the same machine and an identical copy of the database. The database is perfectly accessible from the outside, testing the connectionstring from C# succeeds. I tried access using my windows user as well as SQL authentication using sa and its password. All test succeed, but when I try to run the application it fails giving the error message:
...Named Pipes Provider, Error: 40..
I am using SQL Server 2019, standard port, all protocols activated. The users I tried are sysadmins (since I only want to make some modifications to my application, security is not important at the moment).
It looks as if I had no local access to my database from a C# application - I am using Office 365. Any idea what I can do to make my application work locally?
Thanks so much!

Check this troubleshooting guide from MS even when it says it's for connecting to instances on a different host.
If you already validated that all protocols are enabled, you should check the connection string you're using. You can try the following:
Specifying localhost or the host name will use shared memory so you shouldn't get any error related to named pipes.
Use the pipe path (you can find it in the SQL Server Configuration Manager - > SQL Server Network Configuration -> Protocols for -> Named Pipes -> Properties -> Pipe Name
Use the IP of the host and specify the port number (1433 if it's the default one)

Related

INFORMIXSERVER does not match either DBSERVERNAME or DBSERVERALIASES

I have installed the Informix Client SDK. Then I created a simple .net console application referencing IBM.Data.Informix.dll. When I call IfxConnection.Open() it throws an exception.
ERROR [HY000] [Informix .NET provider][Informix]INFORMIXSERVER does
not match either DBSERVERNAME or DBSERVERALIASES.
sqlerrm(database)
I have seen this post and I can't seem to find the sqlhosts file in the client machine. Also I can't the environment variables mentioned the post as well.
So my questions are:
How to create the sqlhosts file and where will it be saved? Will this be in the database server or client machine or both?
What are the environment variables needed?
In a Windows machine the needed configuration is defined by the Setnet32 utility (installed with the Informix Client SDK). You need to set your Informix instance values in that utility for the connection provider to work (Informix .NET Provider).
First define your "Host Information" in the third tab and then click apply (btw I'm in a spanish Windows machine!):
Note: The "Current Host" value should be added to your hosts Windows file (%WINDIR%\System32\drivers\etc\hosts).
Afterwards, define your "Server Information" in the second tab:
IBM Informix Server is your Informix instance name (INFORMIXSERVER).
Hostname is populated with the hosts defined in the previous step (third tab).
Protocolname is the protocol used to communicate with your server (if you're using an unsecured TCP connection, it could be 'olsoctcp' or 'onsoctcp'. Refer to the official documentation to check which value to use).
Service name is the name used for your server communication service, which should be added to your services Windows file (%WINDIR%\System32\drivers\etc\services)
After these changes you should be able to run your .NET application. Obviously your connection string values should match the information defined in this utility.

.Net - Remote BizTalk server monitoring using WMI when the SQL server is located on another VM

I have created a windows service to monitor receive location and send port events i.e. start/stop/enabled/disabled/enlisted/unenlisted for a local BizTalk server machine using a WMI ManagementScope class scope:
string strScope = #"\\.\root\MicrosoftBizTalkServer";
But when I try pointing at a remote machine/server to capture events using:
string strScope = string.Format(#"\\{0}\root\MicrosoftBizTalkServer", node.Address);
I receive an odd WMI error. The typical remote machine I am trying to point towards is a similar windows server with one small distinction that its BizTalk server is pointing to a SQL server located on yet another server within the network.
After a lot of googling and searching, I came across information pointing at a possible cause of failure being the classic "Double-hop" issue which occurs when we try to access remote BizTalk server when its SQL server is on another machine.
Within visual studio I was not getting enough information on the error that I tried a windows built-in tool "wbemtest.exe" to troubleshoot what was going on only to uncover a long error message such as this:
BizTalk Server cannot access SQL server. This could be due to one of the following reasons:
\n1. Access permissions have been denied to the current user. Either log on as a user that has been granted permissions to SQL and try again, or grant the current user permission to access SQL Server.
\n2. The SQL Server does not exist or an invalid database name has been specified. Check the name entered for the SQL Server and database to make sure they are correct as provided during SQL Server installation.
\n3. The SQL Server exists, but is not currently running. Use the Windows Service Control Manager or SQL Enterprise Manager to start SQL Server, and try again.
\n4. A SQL database file with the same name as the specified database already exists in the Microsoft SQL Server data folder.
\n
\nInternal error from OLEDB provider: \"Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.\""
I have tried playing with Firewall and DCOM setting under Administrative Services -> Component Services but no setting is working for me to pass on my user's credentials via "impersonation" and retrieve back receive location / send ports information.
Please share a workaround/solution/configuration settings that actually addresses this issue.
After a lot of research and thorough study, the solution was achieved via enabling / configuring Kerberos authentication for the non-domain admin. service account user and machines involved in communication i.e. client (machine sending WMI based request), Biztalk node (machine responding to the WMI based request) and SQL Server node (machine hosting / running SQL Server database engine service and most importantly Biztalk's databases which include messagebox, tracking, management and SSO).
This was all done under a single domain and delegation was setup for both the Biztalk node and SQL Server node along with the service account used.
DCOM permissions were granted to the service account for WMI and DTC(Distributed Transaction Coordinator) permissions were setup.
Appropriate SPNs were generated and appropriate SQL Server permissions were granted to the service account initiating WMI request in delegation mode.
Verified that Kerberos was enabled for the particular service account using the following SQL query:
select session_id,net_transport,client_net_address,auth_scheme from sys.dm_exec_connections
This is a double hop issue only, the problem you are facing is because you are trying to run a service and access remote server BizTalk server, which is then trying to logon to a remote SQL server. Your credential only reaches to BizTalk server but BizTalk server does not pass your credentials to another server.
Refer to this link for solution
Similar Issue

Access ASP.NET with database running on localhost through LAN

I am using Microsoft Visual Studio 2013 Ultimate.
I have one C# application connected with WSN to collect and save all sensor readings in database. It is working fine and stable.
Later I decided to add ASP.NET application (developed in the same software) so other computers in LAN can access my page and check measurements. I have one web form with few labels and buttons to ensure move forward and backward through the database table. It is working fine when I start it from Visual Studio but when I am trying to access from IIS it does not work.
I have this error (main part of the text):
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. Cannot create an automatic instance. See the Windows Application event log for error details.
I have installed IIS and I can access "localhost" from my browser (IIS image appears). I published site with "Publish" option from Visual Studio.
I saw a few very similar questions on this forum but I did not find answer. Can you recognize what can be the problem?
Regards.
I think DeanOC's answer will apply if you are using your windows login to connect to sql server (in connection string you'll have Integrated Security=true) in which case:
In IIS select you web application on the righ side click Advanced Settings a dialogue box will pop up in it you can see which application pool your website is using
Close dialog go to Application Pools, right click the application pool you want and go advanced settings
Change the Identity of the application pool, under Process Model, to your current windows login.
http://www.codeproject.com/Articles/674930/Configuring-IIS-ASP-NET-and-SQL-Server
Everything is well explained. Just follow the procedure and it will be - Yeah, solved. :)
The message implies that either sql server instance you are pointing to is not running or that you are pointing to the wrong sql server instance. If you are able to run the application from visual studio then sql server should be running and that would imply that your connection string is wrong.
During publish, msbuild will run config transforms i.e. if build profile is set to release it will change the connection strings in web.config to those in web.release.config. Check your connection strings in the IIS website and also check you password is correct
You could enable TCP/IP in SQL Server Configuration.
Microsoft SQL Server xxx -> Configuration Tools -> SQL Server Configuration Manager -> Select TCP/IP. Right click and select enable
Therefore, you can connect successfully from your local computer but it fails when you access from IIS of other server.
I think you are trying to access the web page from another computer in the network and not sql server in which case you have to add a binding to your site. By default the site is only bound to localhost port 80 meaning it will only be accessible from within the same machine. You'll need a url with dns entries or a static ip address to use to connect to your machine. Check out IIS bindings:
http://blogs.technet.com/b/chrad/archive/2010/01/24/understanding-iis-bindings-websites-virtual-directories-and-lastly-application-pools.aspx
http://technet.microsoft.com/en-us/library/cc731692(v=ws.10).aspx
because you used attach Mode in this way when one of them is connected to your database other one cannot use it like open file. and only the one who is in the same sever could access to your database.
to solve this problem you have to add your database to your SOL server manager after that you could access to it from many devices use
this connection string
Data Source='server IP';Initial Catalog='database name';Persist Security Info=True;User ID='your user name';password='your password'
please follow this video
enter link description here

SqlConnection stuck on Named Pipes

I'm seeing the following error when attempting to open a DB connection from within my C# application. I realize this error has probably shown up on 100's of questions before. However, in this scenario the error is only showing up on C# apps running on my specific desktop PC. I've scoured the internet via Google and within this website, but I can't find a solution.
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
WHY THIS SCENARIO IS UNIQUE:
I am able to connect to the SQL server from SQL Server Management Studio (SSMS). This application works on another computer and is able to establish a connection to the SQL server from there. So this error scenario is specific to C# applications running on my specific desktop PC. Other apps work (SSMS). Other PC's work.
When I "sniff the wire" using WireShark, the trace shows me that my app is trying to connect via NamedPipes (i.e. \Server\IPC$). I can't seem to force it to use TCP/IP.
THINGS I'VE TRIED:
Re-installed.NET Framework
Re-installed Visual Studio (C# - Express version 2010)
Created an alias within cliconfg.exe.
Is there something I missed?
Here are Connection Strings I've tried...
Data Source=<servername>;Initial Catalog=HIE;Integrated Security=true
Server=tcp:10.240.11.81;Integrated Security=SSPI; database=HIE
Data Source=10.240.11.81,1433;Network Library=DBMSSOCN;Initial Catalog=HIE;User ID=<SqlUserIdThatISetUpAsSysAdmin>;Password=<password>
Here's the code snippet:
_conn = new SqlConnection(); // _conn declared globally
_conn.ConnectionString = <the connection string above>;
_conn.Open();
The most likely scenario is that Windows Firewall is block the SQL Server communication. From MSDN (an article about named pipes, but relevant nonetheless):
Microsoft Windows XP Service Pack 2 enables Windows Firewall, which
closes port 445 by default. Because Microsoft SQL Server communicates
over port 445, you must reopen the port if SQL Server is configured to
listen for incoming client connections using named pipes. For
information on configuring a firewall, see "How to: Configure a
Firewall for SQL Server Access" in SQL Server Books Online or review
your firewall documentation.
Another scenario is that the client configuration on the local machine is not configured correctly. From the run prompt, you can execute cliconfg (the SQL Server Client Configuration Utility) to see the enabled protocols and the aliases that are used for the protocols.
Either redefine your Data Source as suggested by usr's comment, or configure your SQL Server to allow TCP connections (Why would you not allow TCP connections anyway?).
Here is the link to enable TCP on your SQL Server (The accepted answer is where you want to look at):
Enable remote connections for SQL Server Express 2012
Are you running your code off of local disk or a network drive? I encountered a very similar problem where my network drive was not trusted in .Net and that was why my connections failed.

Checking "connectivity" between remote server A and remote server B programmatically

We have a requirement (I believe as part of a post build/deployment verification test (BVT)) to test that remote server A can "connect" to remote server B.
I want to develop a console application using C# on my LOCAL developer VM. This should then "connect" to remote server A. It then needs to check that remote server A can "connect" to remote server B (via the original connection from LOCAL to remote server A).
Currently I have generated a simple "helper" exe that connects to remote server B (using a prior known connection string point to remote server B and SqlConnection classes). The exe is copied to remote server A as part of the build process (at the end). PSEXEC.exe on the build server then remotely starts the "helper" exe on remote server A and checks the %errorcode%. This then determines if the BVT should pass or fail (Then the "helper" exe is then deleted from remote server A).
FYI all machines run Windows Server 2008 R2 x64 Enterprise and are on the same local domain. I am an administrator on all 3 machines.
Remote server A is a web server and remote server B is a SQL database server. The LOCAL machine will/does represent the build server. This test is simple as saying "can the web server connect to the database server". The difficulty is how to do that remotely.
I know I can just do System/integration/end-to-end testing (using Coded UI etc) and we are doing this but want to consider this requirement/test as well (as the servers and network configuration etc are a "shared responsibility" with an external party and we cant guarantee that anything has/will change without our knowledge (other than reacting via Service Desk processes))
The process I have adopted seems OTT but does appear to work (if I close ports etc). Is there a completely .NET way of doing it using TCPCLient classess or something etc? What about doing webservices and hosting them on the webserver and call them from the build server? Other ideas and things to consider more than welcome.
Why not create a test page on the web server that carries out an innocuous operation against the SQL server.
The page might execute a simple query (select top(1) name from person) for example.
I can see web-services tagged in your question. If you want to verify connectivity to a server hosting web services or between a server hosting web services and an underlying back-end server (database for example), the best way to be sure (in my opinion) would be to call an innocuous service that does a simple read. Retrieving WSDLs would not be enough.
You can use Management objects to query and control computers and servers on your domain.
http://msdn.microsoft.com/en-us/library/system.management.aspx
SQL server includes some extra objects specific to managing SQL Server.
http://msdn.microsoft.com/en-us/library/ms220749.aspx
If you have Linqpad:
ManagedComputer mc = new ManagedComputer( "yourserver" );
mc.Dump();
otherwise create a console app and create an instance of ManagedComputer and use the debugger to query the computer's SQL server, to see the sort of information available.
As you can see its a big subject...

Categories