question

nupong avatar image
nupong asked

SQl job::: Insert data to server that spesific the IP address.

In the past, i created the sql job to insert the data to server that is specified by Server name. It work well Our IT team of my company do something with DNS. Now a day, My computer that is running job cannot connect to server by specified name. When I ping the server by name of server, It is no reply. When I ping the same server by IP Address. It is reply. The IT team try to solve this problem but it doesn’t work. So, I tried to insert the data to server that is specified by IP Address. It doesn’t work. It away prompt me error. Is there a way to insert the data to server that is specified by IP Address ? My CODE ------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------- exec sp_addlinkedsrvlogin '[172.31.163.82]','false',NULL,'ICENG','IC2123ENG'; DECLARE @PlantName TABLE ( ID int IDENTITY(1,1) PRIMARY KEY, PlantID nchar(3) ) INSERT INTO @PlantName(PlantID) SELECT DISTINCT [PlantID] From [172.31.163.82].[DCSHEALTHDB].[dbo].[PlantInfo]; DECLARE @Email AS nvarchar(max) = STUFF((SELECT ';' + [UserEmail] FROM [172.31.163.82].[DCSHEALTHDB].[dbo].[UserL] For XML PATH ('')), 1, 1, ''); DECLARE @Title as nvarchar(100); DECLARE @Message as nvarchar(max) = 'Daily Control System Healthy Report of Plant '; /*SET @Message += STUFF((SELECT ';' + PlantID FROM @PlantName For XML PATH ('')), 1, 1, ''); */ SET @Message += char(10) + char(10); SET @Title = 'Daily Control System Healthy Report'; DECLARE @ID as int = 1; DECLARE @PlantCount as int = (SELECT COUNT(ID) FROM @PlantName); WHILE @ID <= @PlantCount BEGIN DECLARE @PlantID as nchar(3) = (SELECT PlantID FROM @PlantName WHERE ID = @ID); DECLARE @IdleTimeFailCount as int = (SELECT COUNT(PlantID) FROM [172.31.163.82].[DCSHEALTHDB].[dbo].[CPUIdleTimeAbnormal] WHERE PlantID = @PlantID and [RecoverStamp] is NULL); DECLARE @CardFailCount as int = (SELECT COUNT(PlantID) FROM [172.31.163.82].[DCSHEALTHDB].[dbo].[CardAbnormal] WHERE PlantID = @PlantID and [RecoverStamp] is NULL); DECLARE @FieldAbnormalCount as int = (SELECT COUNT(PlantID) FROM [172.31.163.82].[DCSHEALTHDB].[dbo].[FieldAbnormal] WHERE PlantID = @PlantID and [RecoverStamp] is NULL); SET @Message += ' ' + @PlantID + ': CPU idle time Abnormal ' + cast(@IdleTimeFailCount as nvarchar(3)) + ' Field(s)' + char(10); SET @Message += ' Card Fail ' + cast(@CardFailCount as nvarchar(3)) + ' Slot(s)' + char(10); SET @Message += ' Field Abnormal ' + cast(@FieldAbnormalCount as nvarchar(3)) + ' Point(s)' + char(10); SET @Message += char(10); SET @ID += 1; END --PRINT @Message; EXEC msdb.dbo.sp_send_dbmail @profile_name= 'DCSHealthyReport', @recipients= @Email, @subject= @Title, @body=@Message; ------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------- thank you
sql
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
KenJ avatar image
KenJ answered
If DNS doesn't correctly resolve your remote server, you can create an alias that will allow your server to continue to connect to that IP address through a linked server using the previous DNS name - https://msdn.microsoft.com/en-us/library/ms190445.aspx Adding linked servers isn't really my specialty but, if you remove the brackets "[]" from `exec sp_addlinkedsrvlogin '[172.31.163.82]'`, the code you posted might work without modification.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.