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...
Related
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)
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
I want to create a windows application in C# and SQL Server, these have two databases one is in local another one in remote. I have 2 doubts:
Is possible to connect remote SQL Server in windows application?
Some time Internet may be not available (may be chance). This time I cannot fetch and store data in remote server, my application not running that time,how can avoid this situation?
Full data available remote server, partial database only in local SQL Server
please share ideas to me.
is possible to connect remote sql server in windows application?
Yes. Provided if remote connection in SQL Server is enabled. See How to enable remote connections in SQL
Some time Internet may be not available (may be chance).This time I
cannot fetch and store data in remote server , my application not
running that time,how can avoid this situation?
Check for connection to your server or catch exception to see if server is unavailable. Write the data on your local server or local XML file and then implement sync logic when ever your server becomes available
I need to scan and locate SQL Server instances on my local LAN based on Ip address list or range and I am looking for the following information:
port on which sql server is listening (regular is 1433/1434 but can be changed),
ip address of the machine,
hostname of the machine where sql server is running,
instance version like 10.5.2500.0
instance name information e.g Joe\SQLExpress
I will not have access to any credentials either windows or sql servers. The bets bet is usng windows authentication but i would prefer a discovery-based approach. Also i don't want to raise false alarms during the scan and the scan has to be non-intrusive. The scan has to perform several vulnerability tests(later on) which will involve inspection and further information and should therefore not require any access credentials for each server.
Moreover, some of the instances may have SQL Server Browser service disabled or may have SQL Server agent service stopped.
I need to be able to query all of the SQL Server instances for a given range of IP addresses. I have been trying to use arguments here:
here
and
here
A C# based solution can also help as long as it returns all instances irrespective of whether SQL Server Browser, or SQL Server agent is running or not.
But I want my scan to be as much non-intrusive as possible.
For SQL Server 2005 and beyond there is a documented and supported way, using WMI, see FAQ: Detecting SQL Server 2005 using WMI. This will detect any installed instance, irrelevant of the fact that is running or not, and w/o opening any connection to the SQL Server itself. Of course it requires appropriate permissions to query the remote machine WMI.
For SQL 2000 the only way is to use unsupported registry hacks (look for specific keys).
I have hosted a web application(Application is in Asp.Net with C# language and Sql server database). Now i want to store data in my local database from my hosted web application.How will be the database connection string...any addition changes in Sql Server..?Please explain..Any reply will be appreciated..
DeEP
from .NET 2 upwards the connection string can be stored in a specific node of the web.config file and not in appSettings as it was done before.
I am not sure about your question because if you try to access a database server located outside the network where you have deployed your ASP.NET application (so the hosting provider's internal network), it won't probably work, even in case your SQL Server is publicly available and open for connections from outside (which is bad, really, really bad...), it would also depend on the hosting company network settings.
How did you connect to the SQL Server during development and for debugging within the development machine?
There are info on how to connect to a SQL Server with a connection string in the web.config here: Using connection strings from web.config in ASP.NET v2.0 but not sure this solves your issue.
Sounds like you need to speak to your network administrator - I'd guess that your firewall will probably be set up stop any attempt to access it from outside of your network.
If your hosting company allow it, you maybe able to set up a VPN between the web server and your local database but this would be a lot of hassle.