Monday, June 12, 2006

Importing a SDO file manually using VB script in MCMS 2002

When i tried to import a large SDO file (18 MB), from Site manager on a machine with Windows 2003 server,MCMS 2002 with Sp1a installed i got the following error:

Error: 0Description: The underlying connection was closed: An unexpected error occurred on a receive. Severity: 5Source: System Debug info: N/A Extra info: N/A Client Source: CImProgress::ProcessPackage Recommended Action: N/A

So i tried to import the SDO file using VB script instead of doing it from site manager and it works, below you will find a file named import.vbs

' VBScript for performing an import operation.

'usage: import.vbs filename.sdo
Dim strROPPath
Dim shell
Dim fso
strROPPath = WScript.Arguments(0)
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
If ( fso.FileExists(strROPPath) ) Then
Call Import(strROPPath)
Else
Call MsgBox(strROPPath, vbCritical, "File Does Not Exist")
End If
'**************************************
'* Routine that does the import.
'**************************************
Sub Import(strROPPath)
Dim pCmsDeployImport
On Error Resume Next
Set pCmsDeployImport = WScript.CreateObject("CmsDeployServer.CmsDeployImport.1")
If ( Err.Number <> 0 ) Then
Call MsgBox(Err.Description, vbCritical, "Import Problem")
Set pCmsDeployImport = Nothing
Exit Sub
End If
pCmsDeployImport.AuthenticateAsCurrentUser()
If ( Err.Number <> 0 ) Then
Call MsgBox(Err.Description, vbCritical, "Import Problem")
Set pCmsDeployImport = Nothing
Exit Sub
End If
Dim pImportOptions
Set pImportOptions = pCmsDeployImport.Options
If ( Err.Number <> 0 ) Then
Call MsgBox(Err.Description, vbCritical, "Import Problem")
Set pCmsDeployImport = Nothing
Set pImportOptions = Nothing
Exit Sub
End If
' Importing the grant rights
pImportOptions.IncludeRightsGroups = 3
pImportOptions.RightsOnAdd = 3
pImportOptions.RightsOnReplace = 2
pImportOptions.IncludeCreatedBy = 2
Dim strReportUrl
strReportUrl = pCmsDeployImport.Import(strROPPath)
If ( Err.Number <> 0 ) Then
Call MsgBox(Err.Description, vbCritical, "Import Problem")
Set pCmsDeployImport = Nothing
Set pImportOptions = Nothing
Exit Sub
End If
' Display the report in the Web browser.
Set shell = WScript.CreateObject("WScript.Shell")
shell.Run "http://localhost" & strReportUrl, 7
Call MsgBox( strReportUrl,vbInformation,"" )
Set shell = Nothing
Set pCmsDeployImport = Nothing
Set pImportOptions = Nothing
End Sub

Thursday, May 25, 2006

Killing all processes in the database 'DBNAME' except those connected throw OSQL in Sql Server

I have to restore a snapshot of a Sql server database daily used in a web site,to do this i must be in exclusive mode and the only user connected to the database, so i came up with this script to kill all processes connected to 'DBNAME' , except connected throw OSQL (my connection):
First of all let's create a procedure to kill db processes:

use master
go
CREATE proc kill_process(

@dname varchar(20))
as
Declare

@did int,
@sid int,
@s nvarchar(128)
select @did = dbid
from master..sysdatabases
where name = @dname
declare spid_cursor cursor for
select spid
from master..sysprocesses
where dbid = @did
and program_name <> 'OSQL-32'
open spid_cursorfetch next
from spid_cursor
into @s
While @@fetch_status = 0
Begin
Select @s = 'Kill '+convert(nvarchar(30),@sid)
exec(@s)
--print @s
fetch next
from spidcurs
into @sid
End
Deallocate spidcurs
GO

Now how to use this procedure:

USE MASTER
go
--Killing all processes in the database 'DBNAME' except those connected throw OSQL

exec proc kill_process 'DBNAME'
go
---set the database to single user mode

sp_dboption 'DBNAME', 'single user', true

now let's do the database restore,and don't forget to remove single user mode while finishing

sp_dboption 'DBNAME', 'single user', false

Wednesday, May 24, 2006

Microsoft SQL Server Migration Assistant for Oracle (SSMA)

I was working on converting an oracle database to SQL Server 2005 using SSMA ,so i remarked that if you have an oracle package and because there is no package in SQL Server,so using SSMA the package conversion is done using the following convention :Package functions will be converted to user-defined functions using PackageName_FunctionName naming convention.Package procedures will be converted to stored procedures using PackageName_ProcedureName naming convention.Package variables are emulated using a table and a set of functions.So you must change the function call in your application from PackageName.FunctionName to PackageName_FunctionName, and the procedure call from PackageName.ProcedureName to PackageName_ProcedureName.