on 2024 Apr 11 11:06 AM
I run my database with:
-x tcpip -xs http(port=88888)
I need to know (from inside DB) on which socket (IP+Port) others can connect to me.
Till now I used always this one: select value from sa_eng_properties() where propname = 'HttpAddresses'
But this query does not work always! In some installations the value is empty (the database is accessible on the socket, but I can inquire the socket).
Is there other reliable way to get this socket?
As sa_eng_properties() does not always give the correct IP (on which the webservices of the database can be called), so the only way is to read the environment variable %COMPUTERNAME%
select xp_getenv('COMPUTERNAME')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is it possible that those installations are using -xs https(port=88888) (note the "https" rather than "http")? In that case I think you want HttpsAddresses.
Also check that the server didn't fail to listen on that port at startup. I think the server would fail to start if it couldn't listen at that port but I'm not certain.
BTW, it's would be more efficient (if you care) to select property( 'HttpAddresses' ) rather than having sp_eng_properties() evaluate a ton of properties just to use one of them :).
One other thing comes to mind: is your comparison always against 'HttpAddresses' exactly and never, say, 'httpaddresses'? If you don't match exactly on a case-sensitive database then you won't find the row. Selecting the property() directly wouldn't have that problem.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually I check both.
select value from sa_eng_properties() where propname in ('HttpAddresses', 'HttpsAddresses')
Otherwise I start the databases always with http (not https).
The only difference (on the installation which not works) is that on this machine more than one Database is running! Could this be a problem?
What does "SELECT * from sp_http_listeners()" reveal? (Note, you can add a database ID as parameter.)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
this statement delivers the same result on both (working and not working machines).
ip_address;port;dbname;uri_prefix
'0.0.0.0';88888;;http://0.0.0.0:88888/DB1/
'::';88888;;http://[::]:88888/DB1/
To get all listeners when you have multiple dbs, you might try something like the following
select * from dbo.sa_db_list( NULL ) cross apply dbo.sp_http_listeners( Number )
The properties related to HPPT/HTTPS/TCPIP "...Addresses" and "...Listeners" seem to work differently here (with a 17.0.11.7432 setup): "...Addresses" does list the IP addresses, too, whereas "...Listeners" seem to list the ports on "all" available IP addresses. Here for a local TCP/IP server:
select @@version, property('TcpIpAddresses'), property('TcpIpListeners'); -- returns 17.0.11.7432; 192.168.101.42:2638; (::):2638;0.0.0.0:2638
So you might need to join with the ...Addresses property to get IP addresses AND ports - but then you are back to the original question. 😕
For some reason, the statement in my original question started to work on the other machine too (on which several databases are running).
select value from sa_eng_properties() where propname = 'HttpAddresses'
Nothing was changed on this machine (except the test/diagnostic statements from the above comments).
For this reason, I find it is safer to go with %COMPUTERNAME%
User | Count |
---|---|
75 | |
10 | |
10 | |
10 | |
10 | |
9 | |
8 | |
7 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.