[點(diǎn)晴永久免費(fèi)OA]如何設(shè)置 SQL Server 連接到其他數(shù)據(jù)庫(kù)或其他服務(wù)器上的數(shù)據(jù)庫(kù)
SQL數(shù)據(jù)庫(kù)查詢簡(jiǎn)單知識(shí)點(diǎn)講解教程下載:
附件:SQL數(shù)據(jù)庫(kù)基礎(chǔ)講解.rar select name as main_info, userdept as remark1, userlevel as remark2, post_name as remark3,dept_all_code as order_sort1 from userinf where not (userdept='離職員工組' or userdept='網(wǎng)管')
上面這句SQL可以調(diào)出系統(tǒng)用戶、所在部門、職級(jí)、崗位,按照部門內(nèi)碼排序,不包括部門離職員工組和網(wǎng)管。 ![]() 同一個(gè)服務(wù)器上同一個(gè)數(shù)據(jù)庫(kù)中調(diào)用某個(gè)表的數(shù)據(jù):
select id as main_info, username as remark1, name as remark2, userdept as remark3, post_name as remark4, input_time as remark5, username as order_sort1, id as order_sort2 from userinf where username='$oabusyusername$' 上面這句SQL可以調(diào)出系統(tǒng)用戶信息,調(diào)出的信息限定為當(dāng)前申請(qǐng)人。 ![]() 同一個(gè)服務(wù)器中跨數(shù)據(jù)庫(kù)調(diào)用其他數(shù)據(jù)庫(kù)中某個(gè)表的數(shù)據(jù):
select id as main_info, username as remark1, name as remark2, userdept as remark3, post_name as remark4, input_time as remark5, username as order_sort1, id as order_sort2 from other_db_name.dbo.userinf where username='$oabusyusername$' 注意:必須確保點(diǎn)晴OA中所用的數(shù)據(jù)庫(kù)訪問(wèn)賬號(hào)有權(quán)限訪問(wèn)其他數(shù)據(jù)庫(kù),點(diǎn)晴OA訪問(wèn)數(shù)據(jù)庫(kù)的用戶信息在根目錄下:global.asa中可以看到,一般建議有跨數(shù)據(jù)庫(kù)查詢的需求時(shí),優(yōu)選采用數(shù)據(jù)庫(kù)管理員賬號(hào)sa,不要使用點(diǎn)晴OA預(yù)置賬號(hào)clicksun。 ![]() 不同服務(wù)器中跨服務(wù)器調(diào)用其他服務(wù)器數(shù)據(jù)庫(kù)中某個(gè)表的數(shù)據(jù):
需要先在OA服務(wù)器中創(chuàng)建一個(gè)到其他數(shù)據(jù)庫(kù)的連接,以管理員身份進(jìn)入點(diǎn)晴OA服務(wù)器,打開(kāi)SQL Server管理器,執(zhí)行以下存儲(chǔ)過(guò)程建立到其他服務(wù)器的數(shù)據(jù)庫(kù)連接:
/*不同服務(wù)器數(shù)據(jù)庫(kù)之間的數(shù)據(jù)操作,創(chuàng)建鏈接服務(wù)器 */
exec sp_addlinkedserver 'OtherDB', ' ', 'SQLOLEDB ', '192.168.*.**,1433';
exec sp_addlinkedsrvlogin 'OtherDB', 'false ',null, 'sa', 'password';
![]() 以上SQL為在OA服務(wù)器上創(chuàng)建一個(gè)到其他數(shù)據(jù)庫(kù)的連接:OtherDB,可以使用自定義的其他名稱,用英文(不要用中文),192.168.*.** 可以為其他服務(wù)器的IP地址或域名,1433為服務(wù)端口,如果是1433則可以直接用IP不用逗號(hào)這個(gè)端口:“,1433”,如果使用其他端口,則需要改成相應(yīng)端口號(hào),下面這個(gè)為訪問(wèn)其他數(shù)據(jù)庫(kù)的用戶名及密碼,將password改成相應(yīng)密碼即可。
然后就可以正常使用以下SQL來(lái)連接到其他服務(wù)器了:
select id as main_info, username as remark1, name as remark2, userdept as remark3, post_name as remark4, input_time as remark5, username as order_sort1, id as order_sort2 from OtherDB.other_db_name.dbo.userinf where username='$oabusyusername$' 參數(shù)解釋:OtherDB (剛剛創(chuàng)建的其他服務(wù)器名稱).other_db_name (其他服務(wù)器上數(shù)據(jù)庫(kù)名稱).dbo (就是dbo,必須保留).userinf (要連接的數(shù)據(jù)表名稱)
注意:跨服務(wù)器調(diào)用數(shù)據(jù)必須要先在SQL Server中對(duì)目標(biāo)SQL服務(wù)器進(jìn)行手工配置連接成功,必須確保點(diǎn)晴OA中所用的數(shù)據(jù)庫(kù)訪問(wèn)賬號(hào)有權(quán)限訪問(wèn)其他數(shù)據(jù)庫(kù),一般建議有跨服務(wù)器查詢的需求時(shí),優(yōu)選采用數(shù)據(jù)庫(kù)管理員賬號(hào)sa,不要使用普通賬號(hào)以免權(quán)限不足而無(wú)法通過(guò)檢測(cè)。
以下命令可以查看上述存儲(chǔ)過(guò)程是否執(zhí)行成功:
select * from sys.servers;
![]() 刪除這個(gè)數(shù)據(jù)庫(kù)連接的方法為執(zhí)行:
exec sp_dropserver 'OtherDB', 'droplogins';
沒(méi)有特殊原因創(chuàng)建后不要?jiǎng)h除這個(gè)連接,否則會(huì)導(dǎo)致上述SQL語(yǔ)句無(wú)法執(zhí)行生效。 該文章在 2023/8/17 16:54:04 編輯過(guò) |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |