还原数据库不会出现这种错误的。 例如: --1备份 BACKUP DATABASE Northwind TO DISK = 'c:\Northwind.bak' --2还原 RESTORE DATABASE TestDB FROM DISK = 'c:\Northwind.bak' WITH MOVE 'Northwind' TO 'c:\test\testdb.mdf', MOVE 'Northwind_log' TO 'c:\test\testdb.ldf'
不好意思看错了楼主意思:楼主是还原成功了,然后程序里调用存储过程报错吧。 请执行下述语句,恢复帐号: declare @usr sysname declare cur cursor for select name from dbname..sysusers where sid>1 open cur fetch next from cur into @usr while @@fetch_status=0 begin exec sp_change_users_login 'auto_fix',@usr fetch next from cur into @usr end close cur deallocate cur
--try declare @usr sysname declare cur cursor for select name from gyt..sysusers where status>0 and name<>'dbo' open cur fetch next from cur into @usr while @@fetch_status=0 begin exec sp_change_users_login 'auto_fix',@usr fetch next from cur into @usr end close cur deallocate cur
例如:
--1备份
BACKUP DATABASE Northwind
TO DISK = 'c:\Northwind.bak'
--2还原
RESTORE DATABASE TestDB
FROM DISK = 'c:\Northwind.bak'
WITH MOVE 'Northwind' TO 'c:\test\testdb.mdf',
MOVE 'Northwind_log' TO 'c:\test\testdb.ldf'
请执行下述语句,恢复帐号:
declare @usr sysname
declare cur cursor for
select name from dbname..sysusers where sid>1
open cur
fetch next from cur into @usr
while @@fetch_status=0
begin
exec sp_change_users_login 'auto_fix',@usr
fetch next from cur into @usr
end
close cur
deallocate cur
declare @usr sysname
declare cur cursor for
select name from gyt..sysusers where status>0 and name<>'dbo'
open cur
fetch next from cur into @usr
while @@fetch_status=0
begin
exec sp_change_users_login 'auto_fix',@usr
fetch next from cur into @usr
end
close cur
deallocate cur
你可以从企业管理器里查看这个SP属于哪个用户,然后在对应的数据库用
sp_change_users_login 'Auto_Fix','用户名'的方式新增一个登录来解决这个问题。