1、打開本地企業(yè)管理器,先創(chuàng)建一個SQL Server注冊來遠(yuǎn)程連接服務(wù)器端口SQL Server。
步驟如下圖:
圖1:
![](/d/20211017/f01a9758a00973a63228c0fcc70b088e.gif)
2、彈出窗口后輸入內(nèi)容。"總是提示輸入登陸名和密碼"可選可不選,如圖2。
圖2:
![](/d/20211017/c85d1af5a17964144432e57eb304d296.gif)
3、注冊好服務(wù)器后,點擊打開。如果是選擇了"總是提示輸入登陸名和密碼"的話再點了確定后會提示輸入用戶密碼,如圖3。
圖3:
![](/d/20211017/74a9bda3f52d58647b9adf4fedd61ea8.gif)
4、進(jìn)入后,選擇到您的數(shù)據(jù)庫,如testdb。在上面點右鍵,"所有任務(wù)">>"導(dǎo)入數(shù)據(jù)",如圖4。
圖4:
![](/d/20211017/33112088e3a04007da53b5b89a00399a.gif)
5、進(jìn)入DTS導(dǎo)入/導(dǎo)出向?qū)?,點擊“下一步”按鈕繼續(xù)
圖5:
![](/d/20211017/72cd1b9d0be4ed38eb1e48b91cc150a6.gif)
6、選擇數(shù)據(jù)源,輸入數(shù)據(jù)源所在的數(shù)據(jù)庫服務(wù)器名稱、用戶名、密碼和要復(fù)制數(shù)據(jù)的源數(shù)據(jù)庫,點擊“下一步”按鈕
圖6:
![](/d/20211017/5a964ffb7d1101dd9f360801d0629134.gif)
7、選擇“在SQL Server數(shù)據(jù)庫之間復(fù)制對象和數(shù)據(jù)”方式,點“下一步”繼續(xù)
圖7:
![](/d/20211017/f5e54529e9d0ed55aea18153850647be.gif)
8、這一步可以把"包括擴(kuò)展屬性"和"排序規(guī)則"兩個選擇上。接著去掉左下的"使用默認(rèn)選項",點擊右下角的"選項"來進(jìn)行配置。
圖8:
![](/d/20211017/4ebda61c63f8590bae330da82b25c752.gif)
9、圖8中點"選項"后會彈出圖9,把"復(fù)制數(shù)據(jù)庫用戶和數(shù)據(jù)庫角色"與"復(fù)制對象級權(quán)限"兩個選項去掉,
點確定回到圖8接著點"下一步"進(jìn)到圖10。
圖9:
![](/d/20211017/c0e2fbccfe27e7f6161d14985c8e410b.gif)
10、設(shè)定調(diào)度方式,一般選“立即運(yùn)行”就可以,然后點“下一步”繼續(xù)
圖10:
![](/d/20211017/5035b6270083c9062e15f9d7892e3933.gif)
11、點"完成"開始執(zhí)行。
圖11:
![](/d/20211017/1e63632aee4c996db2db1de1fff8d061.gif)
12、正在進(jìn)行數(shù)據(jù)導(dǎo)入中
圖12:
![](/d/20211017/3f4b59520fbf71fa69e19d36202f1b26.gif)
13、如果一切正常,提示成功復(fù)制如圖13,那就大功告成了。
圖13:
![](/d/20211017/184eb26abc53eb03868cc26384d06cd1.gif)
SQL Server 導(dǎo)入/導(dǎo)出 錯誤排查
如果提示導(dǎo)入失敗,出現(xiàn)圖14情況,這時不要急著點"完成"關(guān)閉窗口。雙擊中間的"出現(xiàn)錯誤"會出現(xiàn)詳細(xì)的失敗原因。
圖14:
![](/d/20211017/6f56e514bea71fcea85dcc22459aef5b.gif)
錯誤原因一、沒安裝SP3補(bǔ)丁
如果是出現(xiàn)如圖15的報錯原因,那么就很有可能是因為您本機(jī)的SQL Server還沒有打SP3補(bǔ)丁。
圖15:
![](/d/20211017/485fb6188e47c4f3af9aab6cb06c3bb5.gif)
如何查看是否已打了SP3補(bǔ)丁呢?右鍵點擊本地SQL Server屬性,彈出圖16窗口,查看"產(chǎn)品版本"一行。
像以下圖顯示8.00.760(SP3)說明已經(jīng)打過補(bǔ)丁。如果您的企業(yè)管理器顯示的版本要比這個小,那就是沒打SP3補(bǔ)丁。
請安裝SQL Server SP3補(bǔ)丁后再重試。
圖16:
![](/d/20211017/a71951c204872790f5d3fada8be02090.gif)
錯誤原因二、對象屬性沖突
如果出現(xiàn)圖17情況,那么應(yīng)該就是您本地數(shù)據(jù)庫的表/視圖/存儲過程的屬主和服務(wù)器上數(shù)據(jù)庫默認(rèn)用戶不一致。
服務(wù)器的用戶一般是:數(shù)據(jù)庫名+'_f',如我的數(shù)據(jù)庫名稱是testdb,則我在服務(wù)器上使用的數(shù)據(jù)庫用戶名就是testdb_f。
如圖18,我本地的表屬主是testuser,與服務(wù)器數(shù)據(jù)庫用戶名不一致,因此導(dǎo)入過程出錯。
圖17:
![](/d/20211017/64ead4cfca0d290da77ae8014a31d28f.gif)
圖18:
解決方法是:
應(yīng)該先把本地的所有表/視圖/存儲過程屬主都改為dbo或testdb_f(后者需要在本地創(chuàng)建起相應(yīng)用戶。
建議創(chuàng)建,否則以后想從服務(wù)器上導(dǎo)出數(shù)據(jù)時同樣會因為這個問題導(dǎo)出錯誤),再重新進(jìn)行導(dǎo)入/導(dǎo)出。
打開SQL查詢分析器,運(yùn)行以下命令進(jìn)行批量修改表屬主為dbo:
exec sp_MSForEachTable 'sp_changeobjectowner "?", "dbo"'
運(yùn)行成功后表屬主會改變成如圖19:
圖19:
![](/d/20211017/dae0d05f1fb5fea0c49b21b7b0ba97fa.gif)
如果需要修改視圖/存儲過程,則麻煩了點。
下面有個方法可以實現(xiàn):
一、先在master創(chuàng)建一個sp_MSforeachObject存儲過程,命令如下:
USE MASTER
GO
CREATE proc sp_MSforeachObject
@objectType int=1,
@command1 nvarchar(2000),
@replacechar nchar(1) = N'?',
@command2 nvarchar(2000) = null,
@command3 nvarchar(2000) = null,
@whereand nvarchar(2000) = null,
@precommand nvarchar(2000) = null,
@postcommand nvarchar(2000) = null
as
/* This proc returns one or more rows for each table (optionally, matching @where), with each table defaulting to its
own result set */
/* @precommand and @postcommand may be used to force a single result set via a temp table. */
/* Preprocessor won't replace within quotes so have to use str(). */
declare @mscat nvarchar(12)
select @mscat = ltrim(str(convert(int, 0x0002)))
if (@precommand is not null)
exec(@precommand)
/* Defined @isobject for save object type */
Declare @isobject varchar(256)
select @isobject= case @objectType when 1 then 'IsUserTable'
when 2 then 'IsView'
when 3 then 'IsTrigger'
when 4 then 'IsProcedure'
when 5 then 'IsDefault'
when 6 then 'IsForeignKey'
when 7 then 'IsScalarFunction'
when 8 then 'IsInlineFunction'
when 9 then 'IsPrimaryKey'
when 10 then 'IsExtendedProc'
when 11 then 'IsReplProc'
when 12 then 'IsRule'
end
/* Create the select */
/* Use @isobject variable isstead of IsUserTable string */
EXEC(N'declare hCForEach cursor global for select ''['' + REPLACE(user_name(uid), N'']'', N'']]'') + '']'' + ''.'' + ''['' +
REPLACE(object_name(id), N'']'', N'']]'') + '']'' from dbo.sysobjects o '
+ N' where OBJECTPROPERTY(o.id, N'''+@isobject+''') = 1 '+N' and o.category ' + @mscat + N' = 0 '
+ @whereand)
declare @retval int
select @retval = @@error
if (@retval = 0)
exec @retval = sp_MSforeach_worker @command1, @replacechar, @command2, @command3
if (@retval = 0 and @postcommand is not null)
exec(@postcommand)
return @retval
GO
二、再運(yùn)行以下命令批量修改表、觸發(fā)器、視圖、存儲過程的屬主(需要先在master創(chuàng)建sp_MSforeachObject存儲過程) EXEc sp_MSforeachObject @command1="sp_changeobjectowner '?', 'dbo'",@objectType=1
EXEc sp_MSforeachObject @command1="sp_changeobjectowner '?', 'dbo'",@objectType=2
EXEc sp_MSforeachObject @command1="sp_changeobjectowner '?', 'dbo'",@objectType=3
EXEc sp_MSforeachObject @command1="sp_changeobjectowner '?', 'dbo'",@objectType=4
此時再重新進(jìn)行導(dǎo)入應(yīng)該就能一切順利了。
您可能感興趣的文章:- SQLSERVER簡單創(chuàng)建DBLINK操作遠(yuǎn)程服務(wù)器數(shù)據(jù)庫的方法
- MSSQLSERVER跨服務(wù)器連接(遠(yuǎn)程登錄)的示例代碼
- 遠(yuǎn)程連接SQLSERVER 2000服務(wù)器方法
- sqlserver 2000 遠(yuǎn)程連接 服務(wù)器的解決方案
- SQL Server 遠(yuǎn)程連接服務(wù)器詳細(xì)配置(sp_addlinkedserver)