I'm trying to get a variable for local IP that the SQL Server Agent can use in a table - sql

I'm writing an insert into a linked server table that includes the IP the of the local server. When SSMS into the server and exec the SP, it provides the correct information into the Linked table.
When the SQL Agent runs the job for itself its returning 'NULL' and inserting Null into the remote table instead of the local IP. I'm sure this is because there is no "local" IP being used as it is using its only ports ect.
Specifically talking about the Connectionproperty('local_net_address)
set #vcLocalIP= convert (varchar,CONNECTIONPROPERTY('local_net_address'))
Any Help or Ideas on this would be greatly appreciated. Just trying to craft this SP so it can be put on different servers and all return the relevant information with as little "manual" intervention as possible.

Related

I am not able to see QH_CLIENT_WORKSTATION_NAME column, it is Null. I'm querying fron Aginity connected on Netezza server

I would like to start monitoring our system closely as to see who and at what time did a user run a query.
Currently, on the tables from HIST DB, we are able to see the query Texts, username, date, time, and client IP. But what we are more interested in is to see the client host machine name.
When we run a query requesting client hostname, the output comes as unknown.
Below is the query that we are running to get our required information:
SELECT *
FROM NZ_QUERY_HISTORY
Is there anything else that we can look at or implement for us to be able to see client machine name.
FYI: When we run: show session all; we do infact see the client host machine.
We did our own view on top of the query history database when we started using netezza a few years ago, and it does not include the DNS name (hostname) of the client. I guess we left it out because it is empty most of the time. Another guess is that our DNS setup doesn’t not allow reverse DNS lookups for all IP addresses from the netezza host.
Instead we rely on:
the clien IP address and netezza username
the username&ip address on the client machine
In total that is quite powerfull
Furthermore we add a bit if ‘pre sql’ to the connection configuration of the client tools we use (sas, powercenter, business objects, etc) and add as much info as we can to the 4 ‘client_application_*’ variables. See here for syntax: https://www.ibm.com/support/knowledgecenter/en/SSULQD_7.2.1/com.ibm.nz.dbu.doc/r_dbuser_set.html
For powercenter we add the workflow,session and other -names...

Automatic change of linked server name for a newly restored database

We are requesting backup/restore from PROD to TEST environment. Is there a way to update the linked server name of Stored Procedures pointing to Test server.
For example:
one stored procedure(prod) used a linked server like [prodservername].[database].[table]
once this stored procedure restored in test then i need to edit the linked server used in stored procedure to [testservername].[database].[table].
The thing is we have a lot of SP that used linked server in calling some data and we don't want to do that manually. Is there a way to automate this process? Please help thanks!
SELECT
column1,
column2,
column3
FROM
[ProductionServerName].[Database].dbo.[Table] --Need to change [ProductionServerName] to [TestServerName]
WHERE column1 = 'Sample'
#Meow3301, seems You are not familar with sql server. Please check below screen cap:
What you need to do is delete the existing one from Server Objects -> Linked Server and re-create the Linked Server with YOUR [ProductionServerName] and change the Data source to your TEST server (no matter the server name or ip address), that's all!

SQL Server linked-server - cannot see all of the rows in target server's database table

I can't see all of the rows in the linked-server's tables. So if I run select count(*) from cmrez.dbo.reservations on the target server itself it returns 809472, but if I run the same query from a remote (linked) server I only get 78324. What's up with that!?
I seem to have come up with a solution. The target server supports mixed-mode logins, so I created a new login and I specify for the linked server to use that login and it appears to work. I don't know why I couldn't use pass-through security, but that doesn't matter as long as it works ;-).

How can I connect to an external database from a sql statement or a stored procedure?

When running a SQL statement or a stored procedure on a database, can you connect to an external database and pull data from there?
something like:
SELECT a.UserID, b.DataIWantToGet
FROM mydb.Users as a, externaldb.Data as b
You'll need to setup a Linked Server instance. Then you can reference the external database as though it were a SQL Server database.
Yep -- there's two methods: either use the function OPENROWSET, or use linked servers. OPENROWSET is useful for ad-hoc single statements, but if you're going to be doing this regularly, read up on linked servers as they allow you to do exactly what you've specified in your SQL Statement ... e.g.,
SELECT database.owner.table for local data
SELECT server.database.owner.table for remote data
And yes, you can mix and match to do joins twixt local and remote. Note though that you'll need to be caureul if you do joins against large tables that exist on the remote server as the query could take a long time to exexute...
Yes, you can. You should take a look at linked servers for starters. You can also use OPENROWSET to hit them directly with no linked server.
Easiest way :
Click connect to server
when it asks for server name use:
192.168.X.X,1433\SQLEXPRESS insted of YOURPC\SQLEXPRESS
(The ip and opened port of target sql server)
Type correct username and password
Done!

how to access table across multiple data server

I have two Sysbase servers , server1 and server2 . I have a stored procedure declared and running on server1. In that SP i want to access table from server2. How can i do that? Also my both instances are running in a UNIX box
You can do that, read more about "Proxy tables" at Sybase Infocenter (search for: create proxy_table statement) Afaik, there has to be remote server declared as well. I think it's documented well.
First, create a 'Remote Server' in the database that has the stored procedure.
You will need to tell it what the 'Server Type' is and how to connect (ODBC, for instance), then in the connection information, you can simply put the DSN name.
Now, you can create proxy tables to reference tables in your other server.
Try using the four part name. See here: http://www.dbforums.com/sybase/1001475-call-sql-server-stored-proc-sybase.html