SQL




Database Restore Error:


1)



The Backup version is different from the current version you are restoring . use the same or Higher version.



2)



Solution:
use master
database restore error:

use master
RESTORE DATABASE Corvi
FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.NAV7\MSSQL\Backup\13-jan.bak'
WITH replace,MOVE 'corvi' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.NAV7\MSSQL\DATA\corvi.MDF',
MOVE 'corvi_Log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.NAV7\MSSQL\DATA\corvi_Log.LDF'


Attach & Detach sql database using query
Attach:
USE master;
GO  IF NOT EXISTS (SELECT * FROM sys.databases WHERE name ='DatabaseName')
 EXEC sp_attach_db 'DatabaseName',       'Path\DatabaseName.mdf', --data file path     
'Path\DatabaseName.ldf'; --log file path
GO
Detach:
USE master;
 GO 
 IF NOT EXISTS (SELECT * FROM sys.databases WHERE name ='DATABASENAME')
  EXEC sp_attach_db ' DATABASENAME ',
         'E:\DATABASENAME.mdf', --data file path 
         'E:\DATABASENAME _0.ndf',
         'E:\DATABASENAME.ndf',
         'E:\ DATABASENAME _2.ndf',
         'E:\ DATABASENAME _3.ndf',
   'E:\DATABASENAME _4.ldf'
    GO  




Error:
Error traceflag 4616 at start N

sql query:

DBCC TRACEON (4616,-1)



Change log entry

query1:

declare @filename as varchar(80)
declare @cmd as varchar(20)
declare @sql as varchar(2000)
declare @query as varchar(4000)

set @filename='"D:\Change Log Backup\MRPL2009\Changelog_' + convert(varchar (10),GETDATE(),112)+ '.csv"'
set @cmd='sqlcmd'
set @sql=' -S "SQL\SQLINSTANCE" -d "MRPL2009" -E -Q "Select * from [MRPL$Change Log Entry]" -o ' + @filename +' -s","'
set  @query= @cmd+@sql

exec master..xp_cmdshell @query

query 2:
Truncate table [MRPL$Change Log Entry]


SQL BACKUP Query

DECLARE @file_name nvarchar(255)
DECLARE @backup_name sysname
DECLARE @backup_descr nvarchar(255)

-- build the filename for the backup
SELECT @file_name = N'F:\Live Backup\MSCRM\MSCRM_' + DATENAME(weekday, getdate()) + N'.bak'
-- set name and description
SELECT @backup_name = N'Backup of MSCRM'
SELECT @backup_descr = N'Scheduled backup of database MSCRM'

-- perform the database backup
BACKUP DATABASE [Robosoft_MSCRM]
TO  DISK = @file_name
WITH INIT, NOUNLOAD, NAME = @backup_name, NOSKIP, DESCRIPTION = @backup_descr, NOFORMAT



Sql Backup Restore Error:
use master
go
alter database Cronus
set single_user with rollback immediate
go
alter database Cronus
set multi_user
go
RESTORE DATABASE Cronus
 FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Backup\Cronusbackup.bak'
 with replace




To Reset Sa or Other User Password in sql server Management studio:

GO
ALTER LOGIN [sa] WITH DEFAULT_DATABASE=[master]
GO
USE [master]
GO
ALTER LOGIN [sa] WITH PASSWORD=N'NewPassword' MUST_CHANGE
GO


make sure that you have enabled "Enfore Password Expiration"


Error:
You are not authorized to sign in. Verify that you are using valid credentials and that you have been setup as a user in Microsoft Dynamics NAV.

USE [Database Name]  
GO
delete from [dbo].[User] 
delete from [dbo].[Access Control] 
delete from [dbo].[User Property] 
delete from [dbo].[Page Data Personalization] 
delete from [dbo].[User Default Style Sheet] 
delete from [dbo].[User Metadata] 
delete from [dbo].[User Personalization] 

1 comment:

  1. sELECT creation_time ,last_execution_time ,total_physical_reads ,total_logical_reads ,total_logical_writes , execution_count , total_worker_time , total_elapsed_time , total_elapsed_time / execution_count avg_elapsed_time ,SUBSTRING(st.text, (qs.statement_start_offset/2) + 1, ((CASE statement_end_offset WHEN -1 THEN DATALENGTH(st.text) ELSE qs.statement_end_offset END - qs.statement_start_offset)/2) + 1) AS statement_text FROM sys.dm_exec_query_stats AS qs CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) st ORDER BY total_elapsed_time / execution_count DESC;

    ReplyDelete