I have two SQL Server. I want to get data from the first one to the second and to update the first with value sent=1 there are not on the same area
What I want to do exactly is a transation in vb.net that can union all the query that will be applicated to the both db
Is it possible because if I put the query of the first db in a transaction and if i make if transaction = true then execute the second truncation (that applicated to the second db) if I lost the connection that may because problem any one can help me to join all the querys on the same transaction
In VB you would use the TransactionScope class to wrap your data access operations. It will create a local transaction to begin with and then promote it to a distributed transaction when required. The SQL Server Distributed Transaction Manager must be active for that to be possible, so that's something for you to read up on.
Related
i have cloud based solutions (azure function, which reads json from service bus and convert to c# object) which inserts data into on prem sql server with multiple insert statements, are sql transactions reliable and secure over the internet.
what if connection fails during insertion in to database.
When connection fails during insertion, transaction is not complete and no rows are inserted.
When you call INSERT inside transaction, no rows are inserted until you call COMMIT TRANSACTOIN. If you use EF and transaction is not commited on end of using block, rollback is called automatically.
This is one of the typical scenario the transactions are designed for.
I am working on a large SQL Server stored procedure which is called by an integration engine, of which I have no access to the IE code (probably VB6) and I know it initiates a SQL Server transaction from this IE code (it rolls back the changes made by the stored procedure). I know SQL Server ignores the commits of inner transactions (at least that is what I have read on the MSDN site)
https://msdn.microsoft.com/en-us/library/ms189336.aspx
But does that count for transactions initiated in calling code that isn't SQL Server / T-SQL code ?
What I am trying to achieve is a database based logging system inside both Oracle and SQL Server stored proc, where the logging wont be rolled back if the update code fails. I have no control over the outer transaction and I cant partially commit the outer transaction , it has to be all or nothing for the outer transaction. I have no control of the outer. For SQL Server , I believe writing an extended stored procedure that simply writes to a table, maybe a solution that isolates itself from the outer transaction
Inside a transaction that have a savepoint I have to make a join with a table that is in a linked server. When I try to do it, I get the error message:
“Cannot use SAVE TRANSACTION within a distributed transaction”
The remote table data rarely changes. It is almost fixed. Is is possible to tell SqlServer to exclude this table from the transaction? I've tried a (NOLOCK) hint, but it isn't possible to use this hint for a table in a linked server.
Does anyone knows about a workaround? I'm using the ole SqlServer 2000.
One thing that you could do is to make a local copy of the remote table before you start the transaction. I know that this may sound like a lot of overhead, but remote joins are frequently a performance problem anyway and the SOP fix for that is also to make a local copy.
According to this link, the ability to use SAVEPOINTs in a Distributed transaction was dropped in SQL 7.
To allow application migration from Microsoft SQL Server 6.5 when
savepoints inside distributed transactions are in use, Microsoft SQL
Server 2000 Service Pack 1 introduces a trace flag that allows a
savepoint within a distributed transaction. The trace flag is 8599 and
can be turned on during the SQL Server startup or within an individual
session (that is, prior to enabling a distributed transaction with a
BEGIN DISTRIBUTED TRANSACTION statement) by using the DBCC TRACEON
command. When trace flag 8599 is set to ON, SQL Server allows you to
use a savepoint within a distributed transaction.
So unfortunately, you may either have to drop the bounding ACID transaction, or change the SPROC on the remote server so that it doesn't use SAVEPOINTs.
On a side note (Although I have seen that you have tagged it SQL SERVER 2000) but to make a point that SQL SERVER 2008 has remote proc trans Option for this.
In this case if the distributed table is not too large I would copy it to a temp table. If possible, include any filtering to get the number of rows to a minimum. Then you can proceed normally. Another option since the data changes rarely is copy the data to a permanant table and checking if anything has changed to prevent sending to much data over the network every time you run the transaction. You could only pull over the recent changes.
If you wish to handle transaction from UI level and you have Visual Studio 2008/.net fx 3.5 or + framework then you can wrap your logic with TransactionScope Class. If you dont have any frontends and you are working only on Sql Servers kindly ignore my answer...
I have two database say DB_A and DB_B. In DB_A database, table having huge data (few tables are having 2 to 10 million data). I want to move the all table data from DB_A to DB_B database. Please help me on writing stored procedures to move efficiently (fast) the data from one database to another.
The issue is how to handle your transaction logs. It has to write to both, but you should handle it in chunks.
So... Try something like this:
While exists (select * from db1.dbo.tablename)
Begin
Delete top 100 from db1.dbo.tablename
Output deleted.* into dbo.tablename;
Checkpoint;
End
No need to reinvent the wheel, have you considered using SQL Server Replication in order to move your database data?
Using Transactional Replication for example, you could define a Publication of the database tables that you wish to be copied/replicated.
You can then either syncrhonize the data on an ad-hoc basis, using a Snapshot, or if you wish to keep the data up to date in "near real time" then you could use continuous replication.
When to use ado.net and SQL Server transactions?
Are there any reasons why one would choose to use ado.net transactions over SQL Server transactions when there is only one SP or query fired against the database within that transactions.
What if you have multiple resources contributing in the transaction then use ADO.NET (and let DTC/Enterprise Services manage it for you), else can use mssql transaction from the SP.
I wouldn't use ADO.NET transactions if using one call to one stored proc which does one query. The purpose of the ADO.NET transaction would be to wrap the execution of multiple calls in to a single transaction. Your case does not fall in to that criteria.