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.
| Author |
Topic |
|
kernelvn
Starting Member
4 Posts |
Posted - 2007-05-10 : 02:58:33
|
| I need to connect to 1 of 2 database server in an individual situation of Mirroring and failover occur. In this case: t-sql insert data to partnera server, but when failover is happen, it re-direct to partnerb serverHere is my code and the problem is in the red line when using ":connect <servername>" code:declare @ConnectA as smallintdeclare @id as bigint:setvar Database2Mirror Mirroringset @ConnectA = 1set @id = 1while (1 > 0) begin set @id = @id + 1 --print @id begin try if (@ConnectA = 1) begin print 'Connect to A' :connect partnera use $(Database2Mirror) end else begin print 'Connect to B' :connect partnerb use $(Database2Mirror) end insert into dbo.UserInfor (IncreaseNumber) values (@id) end try begin catch print 'Failover happenning when insert number ' + @id; if (@ConnectA = 1) set @ConnectA = 2 else set @ConnectA = 1 continue end catchendEven I tried to put it in IF THEN ELSE but it alway jump to :connect partnerb (the partnerb server is in norecovery status and there for an error of unaccessable happen)Please help hot to control connection to databaserver without using ":connect databaseservername"!! Thanks & Best regards,cvkhanh |
|
|
|
|
|