您的位置:首页 > 数据库

一些SQL语句,远程服务器事务设置

2009-07-16 10:34 971 查看
一:


查询数据库版本的语句






1. SELECT SERVERPROPERTY('ProductVersion'),ServerProperty('ProductLevel'),ServerProperty('Edition');

查询结果: 9.00.1399.06 RTM Developer Edition

2. SELECT ◎◎Version

Microsoft SQL Server 2005 - 9.00.1399.06 (Intel X86) Oct 14 2005 00:33:37 Copyright (c) 1988-2005 Microsoft Corporation Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 2)

这样查询出来的两个版本到底一样吗。按照第二中方法查出来的是sp2的版本。但是第一种结果查出来的不是sp2的版本。

二:Case when ..Then..Else..End

select a.* ,Case when a.name=b.name Then a.name else b.name end
from SDt_yf1..losttimetransaction a,common_yf2_errlog..Organizationunit b

本来想把按照条件的losttimetransaction表中的数据查出来,没想到数据做了笛卡尔机。如果a表有10条,b表有10条,结果是100条。不是想要的10条。所以要么加where条件。要么用其他的方法。

改变后的方法:

select a.* ,a.name=(select b.name from common_yf2_errlog..Organizationunit b where
a.name=b.name)
from SDt_yf1..losttimetransaction a

三:连接两个服务器的语句

(1)假如有两台服务器:一台:YJFGDB01,一台:CMOF08.向CMOF08插入数据

INSERT INTO CMOF08.SDT.DBO.DYEMPSUMM

FROM YJFGDB01.SDT.DBO.DYEMPSUMM

如果报错的话:

Msg 7202, Level 11, State 2, Line 5

Could not find server 'tai' in sysservers. Execute sp_addlinkedserver to add the server to sysservers.

说明没有在你执行语句的那台服务器把对方加进去。解决办法如下:

在其中一台服务器上执行这条语句:“服务器名称”为对方的电脑名称:

Exec sp_addLinkedServer N'服务器名称',N'SQL SERVER'

加入后,

  use master

SELECT * FROM SYS.SERVERS 查看是否加入刚才的服务器名称

(2)

当我做数据库合并的时候,在其中一台服务器中修改另外一台数据库中的数据,不加事务的时候没有问题。

但是我想加上事务,以便发生错误的时候回滚。

当我运行下面的语句时:

set xact_abort on

begin distributed tran gg

insert into sdt.common.dbo.color(colorcode)

values('gg')

出现下面的错误:

OLE DB provider "SQLNCLI" for linked server "alex" returned message "The partner transaction manager has disabled its support for remote/network transactions.".

Msg 7391, Level 16, State 2, Line 5

The operation could not be performed because OLE DB provider "SQLNCLI" for linked server "alex" was unable to begin a distributed transaction.

这个错误说明你这台服务器,或者对方电脑没有配置好MS DTC(Microsoft Distributed Transaction Coordinator 微软 分布式事务协调器)

1。先配置sql server 2005
数据库中的配置:

exec sp_configure 'show advanced options',1

exec sp_configure 'remote access',1

exec sp_configure 'remote admin connections',1

exec sp_configure 'remote proc trans',1


运行了上面这四个语句之后出现下面的提示:说明更改成功

Configuration option 'show advanced options' changed from 0 to 1. Run the RECONFIGURE statement to install.

Configuration option 'remote access' changed from 0 to 1. Run the RECONFIGURE statement to install.

Configuration option 'remote admin connections' changed from 1 to 1. Run the RECONFIGURE statement to install.

Configuration option 'remote proc trans' changed from 0 to 1. Run the RECONFIGURE statement to install.

然后运行:reconfigure with override 更改成功。

然后配置系统上的MS DTC:说明一下(windows xp 中的配置和windows server 2003 中的配置有一点不一样,就是在添加删除的组建中:windows xp 没有Application Server 组件)

2。下面是在windows xp sp2

上的配置图:

(1)开始-设置-控制面板-管理工具-组件服务(或者Run->dcomcnfg 直接进去组件服务)

进入界面点击(Console Root->Componet Services->Computers->My Computer)



(2) Right click My Computer->property->(MSDTC)->(CLICK Security Configuration...)



(3)进去 Security Configuration 界面:

确保选中了下列选项:

Network DTC Access

Allow Remote Clinets

Allow Remote Admnistration

Allow Inbound

Allow OutBound

Enable Transaction Internet Protocal(TIP)Transactions

Enable XA Transactions


DTC Logon Account
一定要设置为

NT Authority/NetworkService


选择

No Authentication Required




到这里设置就完了,完了之后重新启动服务器就ok。

3. windows server 2003 中的设置:

打开添加删除程序如图:click Add/Remove windows componer ->select Application Server ->click Details

-> select Enable network COM+ access, and Enable network DTC access. 其他设置按照windows xp 的设置。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐