Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 Inserting data from one server to another

Author  Topic 

jpatracar
Starting Member

11 Posts

Posted - 2008-12-10 : 20:28:02
Hello all,
Is it possible to do using SQL only? or do I need to develop a .NET application in order to accomplish such task?

Thanks,

Jaime

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-12-10 : 21:33:47
You can do with
SSIS,Export/Import Wizard,Linked server or Opendatasource.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-10 : 21:42:57
or even OPENROWSET
Go to Top of Page

jpatracar
Starting Member

11 Posts

Posted - 2008-12-11 : 19:56:43
Hello,
Thanks for your help guys , it works great when I run it as a single the query (I gave a shot the OPENDATASOURCE command). But it is crashing when I try to insert same data inside a trigger.
Here's the code simplified:
CREATE TRIGGER [mytrigger]
ON [dbo].[table1]
FOR INSERT
AS
BEGIN

BEGIN TRY

INSERT OPENDATASOURCE('SQLNCLI', 'my_connection').[Database].[dbo].[InsertedTable]([col1], [col2], [col3], [col4], [col5], [col6])
SELECT t1.col1, t1.col2, t1.col3, t2.col4, t2.col5, NULL AS col6 FROM table1 t1
INNER JOIN table2 t2
ON t1.col1=t2.col1
INNER JOIN inserted i
ON t1.col1 = i.col1
WHERE t1.mycondition = my_value

END TRY


BEGIN CATCH

IF ERROR_NUMBER() = 515
BEGIN
PRINT ' HAY ALGUNAS COLUMNAS QUE NO ADMITEN NULOS: ' + ERROR_MESSAGE()
END
ELSE IF ERROR_NUMBER() = 8152
BEGIN
PRINT ' SE HA SOBREPASADO EL MAXIMO DE UN CAMPO: ' + CONVERT(VARCHAR(10),ERROR_NUMBER()) + ' ' + ERROR_MESSAGE() + ERROR_MESSAGE()
END
ELSE
BEGIN
PRINT 'TENEMOS EL ERROR NUMERO:' + CONVERT(VARCHAR(10),ERROR_NUMBER())+ ' ' + ERROR_MESSAGE()
END

END CATCH

END


The error that throws me is something like this:
Err=5 The transaction ended in the trigger. The batch has been aborted
8501 MSDTC on server "myserver" is unavailable.

The strange thing is that if I select the "INSERT part" and execute it, works perfectly..even if there are 10k rows.
The same error is thrown everytime the trigger is fired. Do you guys know why? how can I solve that part?
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-12-11 : 20:05:30
Cross-server triggers are really bad for performance.Instead use transaction Replication.
Go to Top of Page

jpatracar
Starting Member

11 Posts

Posted - 2008-12-12 : 14:32:23
Thank you sodeep to point me in the right direction,
I've tested such task and it is working well so far.
But when I try to add a new subscription to a server that has SQL2005 express edition the wizard wont let me continue.
The distributor needs to have the addecuate license (I'm using Development edition)in order to work am I right? and the subscriptions shouldn't be a problem which SQL version have?

Jaime,
Go to Top of Page
   

- Advertisement -