一些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 的设置。
查询数据库版本的语句
:
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 的设置。
相关文章推荐
- 在远程服务器执行sql语句
- (转)在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: SQL 网络接口, error: 26 - 定位指定的服务器/实例时出错)
- oracle:使用cmd命令在远程oracle服务器上执行sql语句
- 使用事务操作SQLite数据库和一些常用的SQL语句
- 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: 命名管道提供程序, error: 40 -
- SqlServer和Oracle中一些常用的sql语句8 触发器和事务
- 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: SQL 网络接口, error: 26 - 定位指定的服务器/实例时出错)
- 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: SQL 网络接口, error: 26 - 定位指定的服务器/实例时出错)
- 关于一些常用SQL设置数据库的语句
- 错误:在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: SQL 网络接口, error: 26 - 定位指定的服务器/实例时出错) 解
- SqlServer和Oracle中一些常用的sql语句8 触发器和事务
- 常用的一些SQL语句
- mysql和oracle在sql语句上的一些区别
- Oracle SQLPlus 一些使用经验记录(设置环境变量和字符串比较)
- 设置sql语句执行时间
- 一些有用的SQL语句
- 关于mybatis支持写多条sql语句,支持事务
- SQL Server中链接服务器将替代远程服务器
- SqlServer和Oracle中一些常用的sql语句6 存储过程
- 你必须掌握的一些常见的SQL语句,包含单表查询、高级查询(连接查询、复合条件查询、嵌套查询)