Is there a 'nice' way to check whether an network host is up
making use of 'plain' SQL? I thought of some MS-SQL specific
command or maybe some getting the return value from a ping script
on the server itself.
Does anyone has an idea on this?
There's two possible ways to take your answer:
1. you want to know if a SQL server is running on an arbitrary host
2. You want to ping an arbitrary host from a SQL server using some query.
you could use dariom's answer.
1a. if you want to query one SQL server from another, you're better off using the "Linked Servers" functionality of SQL Server.
You can use the master.dbo.xp_cmdshell stored procedure to execute PING, which then returns the results as text rows and a status code.
EXEC master.dbo.xp_cmdshell 'ping 192.168.1.1'
I'll assume you mean "plain" SQL and not "palin" :-)
If you're trying to see if SQL is running on a host you could try and connect to the SQL Browser Service by using the SSRP (SQL Server Resolution Protocol) (but this needs to be installed and running on the server).
You could try a "best guess" approach and make a TCP connection to port 1433 (the default port SQL Server's Database Engine). If the port is open, it might be that a SQL Server is listening - you could then try and connect to SQL Server and execute a command (like SELECT ##VERSION or something specific to your application). The problems with this approach:
SQL Server Database Engine can be configured to use a non-standard TCP port.
SQL Server might not even be using TCP - you'd have to connect using named pipes (I'm not sure how that's done).
Some other service could be configured to use TCP port 1433. It doesn't mean that SQL Server is listening.
If port 1433 is open and used by SQL Server, you'll need to provide credentials to connect to it and execute commands.
Essentially, the best guess approach will only really work with SQL Servers under your control.
Related
I have a client for which I am setting up a new SQL Server Express and (on a different computer) connecting their Access front end to that SQL Server. I created an account on SQL Server, changed authentication to SQL Server. I am able to log on to that account with no issues locally (through SQL Server Management Studio) on the server itself, but when I go back to the client machine and try to create either an ODBC connection or connect directly in Linked Table manager, I get the error below. Looking at the error log in SQL Server I can see no failed logins. In Access and/or ODBC I use Servername\SQLEXPRESS, choose SQL authentication and type in the username/password that I created. But it's still being stubborn.
I'm kind of at my wits end with this one. I checked to make sure that login is enabled, that the created database is mapped to this user, but I'm out of answers. Anyone have any ideas? I'm sure it's something really stupid that I'm overlooking, I've used SQL Server for a long time but I'm not an experienced DB Administrator I'm sure it's something really simple I'm overlooking, but I've done this hundreds of times before. And Windows Authentication won't work because it's on a different computer.
To connect to a named instance on SQL Server Express with Servername\SQLEXPRESS, you need:
SQL Server Browser service running,
and its UDP port 1434 open in the firewall.
https://learn.microsoft.com/en-us/sql/sql-server/install/configure-the-windows-firewall-to-allow-sql-server-access
SQL Server Browser service
UDP port 1434
The SQL Server Browser service listens for incoming connections to a named instance and provides the client the TCP port number that corresponds to that named instance.
The fixed TCP port for your instance open in the firewall.
You set this in SQL Server Configuration Manager
https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/configure-a-server-to-listen-on-a-specific-tcp-port
This looks more like a network setting rather than server issue.
Check if all necessary permissions, configuration and settings on your machine running the server are OK to accept external connections.
Usually its the server that is rejecting the connection for security reasons.
Is it possible to run a program in which a SQL Server database has been used in other computers where "SQL Server" has not been install?
Certainly, you'd change the connection string to connect to a remote server like this:
Server=RemoteServerName;Database=DatabaseName;...
and in fact, that's the most common production configuration. A shared database amongst multiple users.
The answer is YES. The only thing you need to do is to point where the Microsoft SQL Server is placed. Of course, you need to configure the server to accept remote connections and that the client you're tring to connect has internet access.
Configure SQL Server to accept remote connections
Guessing that you use c#...
Connection strings for c#
Hi all I installed SQL Server and from the localhost it works in my project however when I tried to access database from another computer It gives 0x80131904 exception. I couldn't find the reason what might be the solution?
Have you tried connecting by specifying the port number as well? Something like,
YourServerName,1433
YourServerName\YourInstanceName,1433
I have assumed it is on the default port. If not change 1433 with appropriate port number and try it.
Make sure your server is enabled for tcp/ip connections and that your computer does not block the SQL server port. Also make sure that you enable the proper authentication methods, ie SQL server auth, integrated, etc.
Is there a 'nice' way to check whether an network host is up
making use of 'plain' SQL? I thought of some MS-SQL specific
command or maybe some getting the return value from a ping script
on the server itself.
Does anyone has an idea on this?
There's two possible ways to take your answer:
1. you want to know if a SQL server is running on an arbitrary host
2. You want to ping an arbitrary host from a SQL server using some query.
you could use dariom's answer.
1a. if you want to query one SQL server from another, you're better off using the "Linked Servers" functionality of SQL Server.
You can use the master.dbo.xp_cmdshell stored procedure to execute PING, which then returns the results as text rows and a status code.
EXEC master.dbo.xp_cmdshell 'ping 192.168.1.1'
I'll assume you mean "plain" SQL and not "palin" :-)
If you're trying to see if SQL is running on a host you could try and connect to the SQL Browser Service by using the SSRP (SQL Server Resolution Protocol) (but this needs to be installed and running on the server).
You could try a "best guess" approach and make a TCP connection to port 1433 (the default port SQL Server's Database Engine). If the port is open, it might be that a SQL Server is listening - you could then try and connect to SQL Server and execute a command (like SELECT ##VERSION or something specific to your application). The problems with this approach:
SQL Server Database Engine can be configured to use a non-standard TCP port.
SQL Server might not even be using TCP - you'd have to connect using named pipes (I'm not sure how that's done).
Some other service could be configured to use TCP port 1433. It doesn't mean that SQL Server is listening.
If port 1433 is open and used by SQL Server, you'll need to provide credentials to connect to it and execute commands.
Essentially, the best guess approach will only really work with SQL Servers under your control.
I am trying to connect to a Microsoft SQL 2005 server which is not on port 1433. How do I indicate a different port number when connecting to the server using SQL Management Studio?
127.0.0.1,6283
Add a comma between the ip and port
If you're connecting to a named instance and UDP is not available when connecting to it, then you may need to specify the protocol as well.
Example: tcp:192.168.1.21\SQL2K5,1443
Another way is to setup an alias in Config Manager. Then simply type that alias name when you want to connect. This makes it much easier and is more prefereable when you have to manage several servers/instances and/or servers on multiple ports and/or multiple protocols. Give them friendly names and it becomes much easier to remember them.
You'll need the SQL Server Configuration Manager. Go to Sql Native Client Configuration, Select Client Protocols, Right Click on TCP/IP and set your default port there.
Using the client manager affects all connections or sets a client machine specific alias.
Use the comma as above: this can be used in an app.config too
It's probably needed if you have firewalls between you and the server too...
On Windows plattform with server execute command:
netstat -a -b
look for sql server processes and find port f.e 49198
Or easier. Connect with dbvisualizer, run netstat -a -b find dbvis.exe process and get port.