I would like to update rows over linked server. I created linked server on my local SQL-Server with this instruction.
I can update rows over Query Analyzer with below code. No error returned and rows update on Linked Server successfully.
UPDATE [LinkedServer].[Database].[dbo].[Table]
SET A = 'A', B = 'B'
WHERE id = 1
But when I created a update trigger to my table on my local sql server like below,
ALTER TRIGGER [TriggerLocalServerTable]
ON dbo.[LocalServerTable]
FOR UPDATE
AS
DECLARE #A varchar(4)
DECLARE #B varchar(4)
DECLARE #id int
BEGIN
SELECT
#A = A,
#B = B,
#id = id
FROM inserted
UPDATE [LinkedServer].[Database].[dbo].[Table]
SET A = #A, B = #B
WHERE id = #id
END
When trigger performed, returns this error like below,
OLE DB provider "SQLNCLI" for linked
server "LinkedServer" returned message
"The partner transaction manager has
disabled its support for
remote/network transactions.". Msg
7391, Level 16, State 2, Procedure
TriggerLocalServerTable, Line 45
The operation could not be performed
because OLE DB provider "SQLNCLI" for
linked server "LinkedServer" was unable
to begin a distributed transaction.
I applied this instruction to local server for solving issue, anything changed.
More details;
if defined my linked server with its
remote ip address.
My local server and Linked Server
not in same domain.
Linked Server Security setting is "Be
made using this security context"
Local server version is Windows
Server 2003 SP2, SQL-Server version is 2005
standart.
Linked server OS version is 2008 and
SQL-Server version 2008 (64 bit).
I couldn't access remote server
with RDP. i can access just from sql
port (1433).
i set linked server "RPC" and "RPC
Out" to "True" from "Security Option".
Do you have any idea to solve this issue.
Thank you very much already now.
Edit:
I solved this issue. Firstly i created a trigger for update on [TriggerLocalServerTable]. This trigger's job is inserting new update fields to a local table. This new table using for updated temp datas. Then i created a job that runs every hour for update fileds on LinkedServer. This job gets data from temp table then update to LinkedServer table's fields.
Regards, Kerberos.
Do you have a Distributed Transaction Coordinator installed on Windows Server? If your update is inside a transaction, it won't work without it.
See
link text
The problem dont lies with SQL Server it is with ODBC Driver.
Go to Start > Settings > Control Panel > Administrative Tools > Data Sources
Open System DSN Tab
Select the driver you have used for Linked Server and click configure
Select Advanced > Flags3 and Uncheck Disable transaction check box
Problem Solved :)
Related
i created a linked Mysql server on SQL server 2008 r2. i'm trying to create a trigger on sql table that automatically updates a field in the linked server table, i have a table called "QFORCHOICE" in sql that has fields "Prodcode,prodname and avqty" and a table "que_for_choie" in mysql that has fields "procode,proname and avqty"
i want the trigger to update the value of "procode" in the linked server if the value of "prodcode" in sql server changes. this is what i have so far but it has errors,
create trigger [QFORCHOICE]
ON dbo.QFORCHOICE
FOR INSERT
AS
DECLARE #prodcode numeric(18,0)
DECLARE #prodname varchar(50)
DECLARE #avqty numeric(18,0)
BEGIN
SELECT
#procode = procode,
#proname = proname,
#avqty = avqty
FROM inserted
update [LINKED_MYSQL].[que_for_choice]
SET prodname=#prodname,avqty=#avqty
WHERE prodcode = #prodcode
end
can anybody please help.
thanks in advance
1- From within a trigger, you shouldn't attempt to access anything external to the current database. It will severely slow down any insert activity, and if there are any networking issues or the remote server is down for any reason, you'll then cause the original transaction to roll back. This is rarely the right thing to do
2- you're making the reliability of your system dependent on the reliability of two servers rather than one (say they both have 99% reliability - your system that ties them together with a trigger now has 98% overall reliability).
We have a linked Server against DB2 on SQL Server 2005.
When we tried putting a simple query result set from the linked sever into a temp table return this error.
OLE DB provider "MSDASQL" for linked server "SOMEDSN" returned message "[IBM][CLI Driver] SQL0998N Error occurred during transaction or heuristic processing. Reason Code = "16". Subcode = "2-8004D026". SQLSTATE=58005
".
Msg 7391, Level 16, State 2, Line 21
The operation could not be performed because OLE DB provider "MSDASQL" for linked server "SOMEDSN" was unable to begin a distributed transaction.
DECLARE #FilterCode varchar(20);
Set #FilterCode = '11122';
Create Table #TmpTable (
Id Int
)
Insert Into #TmpTable
EXEC ('Select A.Id From SCM1.DB2TBL1 A Where A.FilterCode = ?', #FilterCode) At SOMEDSN;
The Exec works just fine with correct result set displayed, but as soon as we tried the result set into the temp table, then we get the error.
I searched here and many other places and tried the followings.
sp_configure 'remote proc trans', 0
On Linked Server Properties > Server Options set "Enable Promotion of Distributed Transactions" to false. I did not see this option.
On Linked Server Properties > RPC, RPC out and distributor are set to value TRUE
Used Openquery, but it cannot use dynamic SQL or pass parameters.
The table contains very many rows. We need to execute the query on the DB2 side to reduce the result set based on the parameter.
Any help would be greatly appropriated!
Have you started the MSDTC service (DTC)?
Under Windows 2008:
From Administrative tools->Component services->Computers->My
computer: Local DTC. Right click Properties, go to the MSDTC tab and
select "Security Configuration".
Enable checkbox for "Network dtc access" and "Allow outbound".
Enable checkbox for "No Authentication Required"
If that does not work, try disabling connection pooling.
Is it possible to modify the table creation date of a table? The date which we see on right clicking a table > properties > Created date or in sys.tables.create_date.
Even though the tables were created months ago, I want it to look like they were created today.
No more than you can change your birthday, and why would you want to ?
You could just
select * into #tmp from [tablename]
drop table [tablename]
select * into [tablename] from #tmp
That would rebuild the table and preserve the structure (to a point). You could script a new table , copy data then drop and rename. As above.
In SQL Server 2000, you could do this by hacking into the system tables with the sp_configure option 'allow updates' set to 1.
This is not possible in SQL Server 2005 and up. From Books Online:
This option is still present in the sp_configure stored procedure,
although its functionality is unavailable in Microsoft SQL Server 2005
(the setting has no effect). In SQL Server 2005, direct updates to the
system tables are not supported.
In 2005 I believe you could "game the system" by using a dedicated administrator connection, but I think that was fixed shortly after RTM (or it needs a trace flag or some other undocumented setting to work). Even using DAC and with the sp_configure option set to 1, trying this on both SQL Server 2005 SP4 and SQL Server 2008 R2 SP1 yields:
Msg 259, Level 16, State 1
Ad hoc updates to system catalogs are not allowed.
Who are you trying to fool, and why?
EDIT
Now that we have more information on the why, you could create a virtual machine that is not attached to any domain, set the clock back to whatever date you want, create a database, create your objects, back up the database, copy it to the host, and restore it. The create_date for those objects should still reflect the earlier date, though the database itself might not (I haven't tested this).
You can do this by shifting the clock back on your own system, but I don't know if I'd want to mess with my clock this way after SQL Server has been installed and has been creating objects in what will become "the future" for a short period of time. VM definitely seems safer to me.
I have one table a in one db server..and table b in another server.
I would like to update the table b using values in table a.
How do I specify the server name in query ?
UPDATE SELECT * from [db1].[dbo].StgMGBPData
SET ASO_Ind = [db2].[dbo].Customer_Names.ASO_Ind,
Company = [db2].[dbo].Customer_Names.Company,
Rpt_Cust_ID = [db2].[dbo].Customer_Names.Rpt_Cust_ID
FROM [db2].[dbo].Customer_Names
JOIN [db1].[dbo].StgMGBPData ON [db2].[dbo].Customer_Names.Src_Cust_ID = [db1].[dbo].StgMGBPData.CustomerID
Try linked server because without linked server you can't use server name in query.
You can use sp_addlinkedserver. See an example here:
EXEC sp_addlinkedserver
#server = 'SERVER',-- your servername
#provider = 'SQLOLEDB',
#srvproduct = '',
#datasrc = 'SERVER', -- your servername
#catalog = 'NHS_032808'
-- your database name which you want to connect
Like that exec the procedure with like that parameter after
you can fire the query in connected database like below.
select * from SERVER.NHS_032808.dbo.tbl_resident_mst
If lack of permissions prevents you from using Linked Server yet you are able to connect to both servers from a client and have the necessary select-permissions on the table in server A and the necessary update/insert permissions on the table in server B, then you could use Micorosoft JET in your client to bridge the servers. Data from server A is pulled out to the client where it is then pushed to server B. This falls under the general category of "heterogeneous joins", which was one of the major strengths of JET in an enterprise (multi-server) scenario. This bridging requires more bandwidth than a Linked Server approach does, but it will get the job done. You would create links in JET to the tables in each server and would thereafter be able to refer to both within the same query.
We have 2 databases, say DB1 and DB2.
DB1 contains all the stored procedures which access also data in DB2.
DB1 uses synonyms to access the tables in DB2.
(Using synonyms is a requirement in our situation)
This works perfectly fine in all situations with SQL Server 2005 Developer Edition.
However in the Express Edition, we get an exception when we do the following:
1 Restart SQL Server
2 Execute the following code within DB1:
set transaction isolation level snapshot
begin transaction
declare #sQuery varchar(max)
set #sQuery = 'Select * from synToSomeTableInDB2'
exec (#sQuery)
commit transaction
This will result in the following error:
Snapshot isolation transaction failed in database '...' because the database was not recovered when the current transaction was started. Retry the transaction after the database has recovered.
The same select query passes fine when used without the EXEC or when run on the Developer Edition.
Restarting the server in step 1 is important as once a connection was made to DB2, the code runs also fine on SQL Server Express Edition.
Does anyone have an idea what this is? We need to be able to use EXEC for some dynamic queries.
We've already checked MSDN, searched Google, ...
Any help is greatly appreciated.
--- Edit: March 10 09
As discussed with Ed Harper below, I've filed a bug report for this.
See https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=422150
As found out via Microsoft Connect, the problem is that by default on SQL Server Express Edition the AUTO_CLOSE option is set on true.
Changing this option to false fixes the problem.
The error message suggests that the query fails because SQL server is still recovering the database following the service restart when you execute your query.
Does the error always occur on the first attempt to run this code, regardless of the time elapsed since the service was restarted?
Can you confirm from the SQL Server log that the database is recovering correctly after the restart?