PeopleSoft - SQL Server clone script

I am working for a county government as a consultant for PeopleSoft using SQL Server. When they restore a DEV instance from PROD, they have to manually stop the web server, app server and batch server, then they do the restore. Afterward they have to change
all references to PROD in the cloned DEV instance. Everything is done manually and takes a couple of hours.
Can anyone point me to scripts for PeopleSoft restores that automate bringing down/up the web, app and batch servers and all the other tasks so they don't have to be done manually?
Life is hard, but it's harder when you're stupid! John 'Duke' Wayne
Life is hard, but it's harder when you're stupid! John 'Duke' Wayne

This question should be posted on PeopleSoft support forum as you are asking scripts to bring down app, web and batch servers and proprietary tasks of cleaning
up the data within tables.
That being said, a quick search on the internet will provide helpful links like below: http://www.erpassociates.com/peoplesoft-corner-wiki/peoplesoft-administration/cloning-a-peoplesoft-database.html
Satish Kartan www.sqlfood.com

Similar Messages

  • SQL Server Backup Script

    Hello all, 
    not sure if I'm on the right thread but if not please do point me to the correct one.
    basically I have a script that run every end of the month to do a backup of a database (Detach, Mount a new, and move the database to a new
    location) bu since this month this is coming back with an error when running it. as far as i know nothing has changed since two or three months ago but this is not longer working. 
    Assistance is really needed. here.
    Here is my code but this is now coming back with
    Msg 5105, Level 16, State 4, Server PRITL1, Line 1 
    Device activation error. The physical file name 
    'E:\SQL\MSSQL\Data\Syslogd.mdf' may be incorrect.
    @echo off
    rem ***************************************************
    rem * This script automates the Syslog Backup process *
    rem ***************************************************
    echo 192.168.0.9 > report.txt
    date /t >> report.txt
    time /t >> report.txt
    blat report.txt -to [email protected] -f [email protected] -subject "Queen - Starting Syslog DB Maintenance" -server 192.168.0.26
    echo ******************************************* >> report.txt
    echo * Stopping the Kiwi Syslog Daemon Service * >> report.txt
    echo ******************************************* >> report.txt
    net stop "Kiwi Syslog Daemon"
    for /F "tokens=3 delims=: " %%A in ('sc query "Kiwi Syslog Daemon" ^| findstr " STATE"') do (
    if /I "%%A" NEQ "RUNNING" (
    echo Stopping the Kiwi Syslog Daemon Service succeeded >> report.txt
    echo. >> report.txt
    ) else (
    echo -----!!! Stopping the Kiwi Syslog Daemon Service failed !!!----- >> report.txt
    blat report.txt -to [email protected] -f [email protected] -subject "Queen - Syslog DB Maintenance Report" -server 192.168.0.26
    exit
    echo ********************************** >> report.txt
    echo * Detaching the Syslogd database * >> report.txt
    echo ********************************** >> report.txt
    ping 127.0.0.1
    ping 127.0.0.1
    osql -E -b -Q "master..sp_detach_db 'Syslogd'" >> report.txt
    set ReturnCode=%errorlevel%
    if %ReturnCode% equ 0 (
    echo Detaching the Syslogd database succeeded >> report.txt
    echo. >> report.txt
    ) else (
    echo. >> report.txt
    echo -----!!! Detaching the Syslogd database failed !!!----- >> report.txt
    echo. >> report.txt
    echo ********************************************* >> report.txt
    echo * Restarting the Kiwi Syslog Daemon service * >> report.txt
    echo ********************************************* >> report.txt
    net start "Kiwi Syslog Daemon"
    for /F "tokens=3 delims=: " %%A in ('sc query "Kiwi Syslog Daemon" ^| findstr " STATE"') do (
    if /I "%%A" NEQ "STOPPED" (
    echo Restarting the Kiwi Syslog Daemon Service succeeded >> report.txt
    blat report.txt -to [email protected] -f [email protected] -subject "Queen - Syslog DB Maintenance Report" -server 192.168.0.26
    exit
    ) else (
    echo -----!!! Restarting the Kiwi Syslog Daemon Service failed !!!----- >> report.txt
    blat report.txt -to [email protected] -f [email protected] -subject "Queen - Syslog DB Maintenance Report" -server 192.168.0.26
    exit
    echo *************************************************** >> report.txt
    echo * Moving the Syslogd database to the _Burn folder * >> report.txt
    echo *************************************************** >> report.txt
    Move E:\SQL\MSSQL\Data\Syslogd*.* \\server\Syslogs2\_Burn\
    set ReturnCode=%errorlevel%
    if %ReturnCode% equ 0 (
    echo Moving the Syslogd database to the _Burn folder succeeded >> report.txt
    echo. >> report.txt
    ) else (
    echo -----!!! Moving the Syslogd database to the _Burn folder failed !!!----- >> report.txt
    echo ************************************ >> report.txt
    echo * Reattaching the Syslogd database * >> report.txt
    echo ************************************ >> report.txt
    osql -E -b -Q "master..sp_attach_db 'Syslogd','E:\SQL\MSSQL\Data\Syslogd.mdf','E:\SQL\MSSQL\Data\Syslogd_log.ldf'" >> report.txt
    echo. >> report.txt
    echo ********************************************* >> report.txt
    echo * Restarting the Kiwi Syslog Daemon service * >> report.txt
    echo ********************************************* >> report.txt
    net start "Kiwi Syslog Daemon"
    for /F "tokens=3 delims=: " %%A in ('sc query "Kiwi Syslog Daemon" ^| findstr " STATE"') do (
    if /I "%%A" NEQ "STOPPED" (
    echo Restarting the Kiwi Syslog Daemon Service succeeded >> report.txt
    blat report.txt -to [email protected] -f [email protected] -subject "Queen - Syslog DB Maintenance Report" -server 192.168.0.26
    exit
    ) else (
    echo -----!!! Restarting the Kiwi Syslog Daemon Service failed !!!----- >> report.txt
    blat report.txt -to [email protected] -f [email protected] -subject "Queen - Syslog DB Maintenance Report" -server 192.168.0.26
    exit
    echo **************************************** >> report.txt
    echo * Restoring the blank Syslogd database * >> report.txt
    echo **************************************** >> report.txt
    osql -E -b -Q "Restore Database Syslogd from disk = 'E:\SQL\MSSQL\Backup\SyslogD_Blank.bak'" >> report.txt
    set ReturnCode=%errorlevel%
    if %ReturnCode% equ 0 (
    echo Restoring the blank Syslogd database succeeded >> report.txt
    echo. >> report.txt
    ) else (
    echo. >> report.txt
    echo -----!!! Restoring the blank Syslogd database failed !!!----- >> report.txt
    echo ************************************ >> report.txt
    echo * Moving back the Syslogd database * >> report.txt
    echo ************************************ >> report.txt
    Move \\server\Syslogs2\_Burn\Syslogd*.* E:\SQL\MSSQL\Data
    echo ************************************ >> report.txt
    echo * Reattaching the Syslogd database * >> report.txt
    echo ************************************ >> report.txt
    osql -E -b -Q "master..sp_attach_db 'Syslogd','E:\SQL\MSSQL\Data\Syslogd.mdf','E:\SQL\MSSQL\Data\Syslogd_log.ldf'" >> report.txt
    echo. >> report.txt
    echo ********************************************* >> report.txt
    echo * Restarting the Kiwi Syslog Daemon service * >> report.txt
    echo ********************************************* >> report.txt
    net start "Kiwi Syslog Daemon"
    for /F "tokens=3 delims=: " %%A in ('sc query "Kiwi Syslog Daemon" ^| findstr " STATE"') do (
    if /I "%%A" NEQ "STOPPED" (
    echo Restarting the Kiwi Syslog Daemon Service succeeded >> report.txt
    blat report.txt -to [email protected] -f [email protected] -subject "Queen - Syslog DB Maintenance Report" -server 192.168.0.26
    exit
    ) else (
    echo -----!!! Restarting the Kiwi Syslog Daemon Service failed !!!----- >> report.txt
    blat report.txt -to [email protected] -f [email protected] -subject "Queen - Syslog DB Maintenance Report" -server 192.168.0.26
    exit
    echo ******************************************* >> report.txt
    echo * Starting the Kiwi Syslog Daemon service * >> report.txt
    echo ******************************************* >> report.txt
    net start "Kiwi Syslog Daemon"
    for /F "tokens=3 delims=: " %%A in ('sc query "Kiwi Syslog Daemon" ^| findstr " STATE"') do (
    if /I "%%A" NEQ "STOPPED" (
    echo Starting the Kiwi Syslog Daemon Service succeeded >> report.txt
    ) else (
    echo -----!!! Starting the Kiwi Syslog Daemon Service failed !!!----- >> report.txt
    blat report.txt -to [email protected] -f [email protected] -subject "Queen - Syslog DB Maintenance Report" -server 192.168.0.26
    exit
    echo ************************************** >> report.txt
    echo * Compressing the Syslog backup file * >> report.txt
    echo ************************************** >> report.txt
    "C:\program files\winrar\rar.exe" M -df -ep -ag -m5 \\server\Syslogs2\_Burn\PR-Syslog \\server\Syslogs2\_Burn\syslogd*.* >> report.txt
    echo. >> report.txt
    set ReturnCode=%errorlevel%
    if %ReturnCode% equ 0 (
    echo Compressing the Syslog backup file succeeded >> report.txt
    echo. >> report.txt
    ) else (
    echo -----!!! Compressing the Syslog backup file failed !!!----- >> report.txt
    blat report.txt -to [email protected] -f [email protected] -subject "Queen - Syslog DB Maintenance Report" -server 192.168.0.26
    exit
    echo **************************** >> report.txt
    echo * Completed * >> report.txt
    echo * Ready for burning! * >> report.txt
    echo * Check Archived files on * >> report.txt
    echo * \\\server\Syslogs2 * >> report.txt
    echo *************************** >> report.txt
    echo. >> report.txt
    date /t >> report.txt
    time /t >> report.txt
    blat report.txt -to [email protected] -f [email protected] -subject "Queen - Syslog DB Maintenance Report - Ready to Burn" -server 192.168.0.26

    Bill thanks for that, 
    this is actually an SQL express edition and not a full SQL server.
    Environment:
    Databases will be detached, copied to from  E:\SQL\MSSQL\Data\ to a shared location and then mount black database foles .MDF
    and .LDF files to the SQL express and then restart the kiwi syslog applications.
     why not powershell? well I've inherited this and machine is a 2003 server and we do not install PS on all machines except
    if they are needed.
    SQLServer Express comes with tools to backup the database.  Post is SQLServer forum to learn how to set up and use SQLExpress tools.
    SQLExpress has support in PowerShell for managing the  server.
    Here si on emethod posted by Microsoft that is useful.  Methods using the scheduler and other tools are available.
    http://support.microsoft.com/kb/2019698
    ¯\_(ツ)_/¯

  • Conversion of SQL Server 2005 script to PL/SQL

    I want to conver the below script into PL/SQL
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[AuditLog]') AND type in (N'U'))
    BEGIN
    CREATE TABLE [dbo].[AuditLog](
         [GroupID] [int] NOT NULL,
         [ID] [int] NOT NULL,
         [TableName] [varchar](25) NOT NULL,
         [FieldName] [varchar](25) NOT NULL,
         [FieldType] [varchar](25) NULL,
         [OldValue] [text] NOT NULL,
         [NewValue] [text] NOT NULL,
         [ChangedOn] [timestamp] NOT NULL,
         [ChangedBy] [int] NOT NULL,
    CONSTRAINT [PK_AuditLog_ID] UNIQUE NONCLUSTERED
         [ID] ASC
    )WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    END
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UserRights]') AND type in (N'U'))
    BEGIN
    CREATE TABLE [dbo].[UserRights](
         [UserID] [int] NULL,
         [MenuName] [varchar](25) NULL,
         [IsEnabled] [int] NULL,
    CONSTRAINT [PK_UserRights_UserID] UNIQUE NONCLUSTERED
         [UserID] ASC
    )WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
    ) ON [PRIMARY]
    END
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GradeMaster]') AND type in (N'U'))
    BEGIN
    CREATE TABLE [dbo].[GradeMaster](
         [ID] [int] NULL,
         [Name] [varchar](25) NULL,
         [Description] [varchar](25) NULL,
         [From] [float] NULL,
         [To] [float] NULL,
    CONSTRAINT [PK_GradeMaster_ID] UNIQUE NONCLUSTERED
         [ID] ASC
    )WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
    ) ON [PRIMARY]
    END
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CostGroup]') AND type in (N'U'))
    BEGIN
    CREATE TABLE [dbo].[CostGroup](
         [ID] [int] NOT NULL,
         [Name] [varchar](25) NOT NULL,
    CONSTRAINT [PK_CostGroup_ID] UNIQUE NONCLUSTERED
         [ID] ASC
    )WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
    ) ON [PRIMARY]
    END
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ToIndex]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
    BEGIN
    execute dbo.sp_executesql @statement = N'
    ** Function dbo.ToIndex
    CREATE FUNCTION [dbo].[ToIndex](@string_to_index VARCHAR(1024))
    RETURNS VARCHAR(1024)
    AS
    BEGIN
    DECLARE @temp VARCHAR(1024)
    DECLARE @ivar VARCHAR(1024)
    DECLARE @tmps VARCHAR(1)
    SET @temp = ''''
    SET @ivar = UPPER(@string_to_index)
    DECLARE @i INTEGER
    SET @i = 1
    WHILE (@i <= LEN(@string_to_index))
    BEGIN
    SET @tmps = SUBSTRING(@ivar, @i, 1)
    IF (ASCII(@tmps) >= 48 AND ASCII(@tmps) <= 57) OR (ASCII(@tmps) >= 65 AND ASCII(@tmps) <= 90)
    BEGIN
    SET @temp = @temp + @tmps
    END
    SET @i = @i + 1
    END
    RETURN @temp
    END
    END
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MasterID]') AND type in (N'U'))
    BEGIN
    CREATE TABLE [dbo].[MasterID](
         [TableID] [int] NOT NULL,
         [TableName] [varchar](25) NOT NULL,
         [NextID] [int] NULL DEFAULT ((1)),
    CONSTRAINT [PK_MasterID_TableID] UNIQUE NONCLUSTERED
         [TableID] ASC
    )WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
    ) ON [PRIMARY]
    END
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UserList]') AND type in (N'U'))
    BEGIN
    CREATE TABLE [dbo].[UserList](
         [ID] [int] NOT NULL,
         [Name] [varchar](25) NOT NULL,
         [Password] [varchar](25) NOT NULL,
         [FullName] [varchar](25) NULL,
    CONSTRAINT [PK_UserList_ID] UNIQUE NONCLUSTERED
         [ID] ASC
    )WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
    ) ON [PRIMARY]
    END
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Product]') AND type in (N'U'))
    BEGIN
    CREATE TABLE [dbo].[Product](
         [GroupID] [int] NOT NULL,
         [ID] [int] NOT NULL,
         [Name] [varchar](50) NOT NULL,
         [GrossMargin] [float] NULL DEFAULT ((0)),
         [RMC] [float] NULL DEFAULT ((0)),
         [Packing] [float] NULL DEFAULT ((0)),
         [Overhead] [float] NULL DEFAULT ((0)),
         [Others] [float] NULL DEFAULT ((0)),
         [TotalCost] [float] NULL DEFAULT ((0)),
         [DPRate] [float] NULL DEFAULT ((0)),
         [CreatedOn] [datetime] NULL DEFAULT (getdate()),
         [CreatedBy] [int] NULL DEFAULT ((1)),
         [UpdatedOn] [datetime] NULL DEFAULT (getdate()),
         [UpdatedBy] [int] NULL DEFAULT ((1)),
    CONSTRAINT [PK_Product_GroupID_ID] UNIQUE NONCLUSTERED
         [GroupID] ASC,
         [ID] ASC
    )WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
    ) ON [PRIMARY]
    END
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RawMaterial]') AND type in (N'U'))
    BEGIN
    CREATE TABLE [dbo].[RawMaterial](
         [GroupID] [int] NOT NULL,
         [ID] [int] NOT NULL,
         [Name] [varchar](50) NOT NULL,
         [CurPrice] [float] NULL,
         [OldPrice] [float] NULL,
         [CreatedOn] [datetime] NULL,
         [CreatedBy] [int] NULL,
         [UpdatedOn] [datetime] NULL,
         [UpdatedBy] [int] NULL,
    CONSTRAINT [PK_RawMaterial_GroupID_ID] UNIQUE NONCLUSTERED
         [GroupID] ASC,
         [ID] ASC
    )WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
    ) ON [PRIMARY]
    END
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Recipe]') AND type in (N'U'))
    BEGIN
    CREATE TABLE [dbo].[Recipe](
         [GroupID] [int] NOT NULL,
         [ID] [int] NOT NULL,
         [WEFDate] [datetime] NOT NULL,
         [ProductID] [int] NOT NULL,
         [RawMaterialID] [int] NOT NULL,
         [Seq] [int] NOT NULL,
         [Quantity] [float] NOT NULL,
         [RMCost] [float] NOT NULL,
         [CreatedOn] [datetime] NULL,
         [CreatedBy] [int] NULL,
         [UpdatedOn] [datetime] NULL,
         [UpdatedBy] [int] NULL,
    CONSTRAINT [PK_Recipe_GroupID_Seq_ProductID_RawMaterialID] UNIQUE NONCLUSTERED
         [GroupID] ASC,
         [Seq] ASC,
         [ProductID] ASC,
         [RawMaterialID] ASC
    )WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
    ) ON [PRIMARY]
    END
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[spCalcGM]') AND type in (N'P', N'PC'))
    BEGIN
    EXEC dbo.sp_executesql @statement = N'-- =============================================
    -- Author:          Mohammed Haris
    -- Create date: 24-12-2006
    -- Description:     RMC Calculator
    -- =============================================
    CREATE PROCEDURE [dbo].[spCalcGM]
         -- Add the parameters for the function here
         @GroupID int,
         @ProductID int,
         @RM_ID int,
         @Price int = 0
    AS
    BEGIN
         --SET NOCOUNT ON
         -- Declare the return variable here
         DECLARE @Result               float
         DECLARE @SumCurPrice0     float
         DECLARE @SumCurPrice     float
         DECLARE @SumOldPrice     float
         DECLARE @SumQuantity     float
         DECLARE @SumRMC               float
         DECLARE @PTotalCost          float
         DECLARE @PDPRate          float
         -- Add the T-SQL statements to compute the return value here
         SELECT     @SumCurPrice0 = SUM(Recipe.Quantity * RawMaterial.CurPrice)
         FROM     RawMaterial INNER JOIN
                   Recipe ON RawMaterial.ID = Recipe.RawMaterialID
         WHERE     (Recipe.ProductID = @ProductID)
              AND (Recipe.RawMaterialID <> @RM_ID)
              AND (Recipe.GroupID = @GroupID)
         /*IF ISNULL(@SumCurPrice0)*/
              SET @SumCurPrice = ISNULL(@SumCurPrice0, 0)
         /*ELSE
              SET @SumCurPrice = @SumCurPrice0*/
         IF @Price = 0
              SELECT     @SumOldPrice = SUM(Recipe.Quantity * RawMaterial.CurPrice)
              FROM     RawMaterial INNER JOIN
                        Recipe ON RawMaterial.ID = Recipe.RawMaterialID
              WHERE     (Recipe.ProductID = @ProductID)
                   AND (Recipe.RawMaterialID = @RM_ID)
                   AND (Recipe.GroupID = @GroupID)
         ELSE
              SELECT     @SumOldPrice = SUM(Recipe.Quantity * RawMaterial.OldPrice)
              FROM     RawMaterial INNER JOIN
                        Recipe ON RawMaterial.ID = Recipe.RawMaterialID
              WHERE     (Recipe.ProductID = @ProductID)
                   AND (Recipe.RawMaterialID = @RM_ID)
                   AND (Recipe.GroupID = @GroupID)
         SELECT     @SumQuantity = SUM(Recipe.Quantity)
         FROM     Recipe
         WHERE     (Recipe.ProductID = @ProductID)
              AND (Recipe.GroupID = @GroupID)
         SELECT     @SumRMC = (@SumCurPrice + @SumOldPrice) / @SumQuantity
         SELECT     @PTotalCost = (Product.Packing + Product.Overhead + Product.Others),
                   @PDPRate = Product.DPRate
         FROM     Product
         WHERE     (Product.ID = @ProductID) AND (Product.GroupID = @GroupID)
         SELECT     @PTotalCost = @PTotalCost + @SumRMC
         SELECT     @Result = (@PDPRate - @PTotalCost) / @PDPRate
         SELECT
              @SumCurPrice0 AS SumCurPrice0,
              @SumCurPrice AS SumCurPrice,
              @SumOldPrice AS SumOldPrice,
              @SumQuantity AS SumQuantity,
              @SumRMC AS SumRMC
         -- Return the result of the function
         RETURN @Result
    END
    END
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_UpdateTotalCostAndGMForAllProducts]') AND type in (N'P', N'PC'))
    BEGIN
    EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE
         [dbo].[sp_UpdateTotalCostAndGMForAllProducts]
    AS
    BEGIN
         UPDATE Product
              SET Product.TotalCost = Product.RMC + Product.Packing + Product.Overhead + Product.Others
         UPDATE Product
              SET Product.GrossMargin = (Product.DPRate - Product.TotalCost) / Product.DPRate
    END
    END
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_UpdateTotalCostAndGMForProduct]') AND type in (N'P', N'PC'))
    BEGIN
    EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE
         [dbo].[sp_UpdateTotalCostAndGMForProduct] (@ProductID int)
    AS
    BEGIN
         UPDATE Product
              SET Product.TotalCost = Product.RMC + Product.Packing + Product.Overhead + Product.Others
              WHERE Product.ID = @ProductID
         UPDATE Product
              SET Product.GrossMargin = (Product.DPRate - Product.TotalCost) / Product.TotalCost
              WHERE Product.ID = @ProductID
    END
    END
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CalcGM]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
    BEGIN
    execute dbo.sp_executesql @statement = N'-- =============================================
    -- Author:          Mohammed Haris
    -- Create date: 24-12-2006
    -- Description:     RMC Calculator
    -- =============================================
    CREATE FUNCTION [dbo].[CalcGM]
         -- Add the parameters for the function here
         @GroupID int,
         @ProductID int,
         @RM_ID int,
         @Price int = 0
    RETURNS float
    AS
    BEGIN
         --SET NOCOUNT ON
         -- Declare the return variable here
         DECLARE @Result               float
         DECLARE @SumCurPrice     float
         DECLARE @SumOldPrice     float
         DECLARE @SumQuantity     float
         DECLARE @SumRMC               float
         DECLARE @PTotalCost          float
         DECLARE @PDPRate          float
         -- Add the T-SQL statements to compute the return value here
         SELECT     @SumCurPrice = SUM(Recipe.Quantity * RawMaterial.CurPrice)
         FROM     RawMaterial INNER JOIN
                   Recipe ON RawMaterial.ID = Recipe.RawMaterialID
         WHERE     (Recipe.ProductID = @ProductID)
              AND (Recipe.RawMaterialID <> @RM_ID)
              AND (Recipe.GroupID = @GroupID)
         SET @SumCurPrice = ISNULL(@SumCurPrice, 0)
         IF @Price = 0
              SELECT     @SumOldPrice = SUM(Recipe.Quantity * RawMaterial.CurPrice)
              FROM     RawMaterial INNER JOIN
                        Recipe ON RawMaterial.ID = Recipe.RawMaterialID
              WHERE     (Recipe.ProductID = @ProductID)
                   AND (Recipe.RawMaterialID = @RM_ID)
                   AND (Recipe.GroupID = @GroupID)
         ELSE
              SELECT     @SumOldPrice = SUM(Recipe.Quantity * RawMaterial.OldPrice)
              FROM     RawMaterial INNER JOIN
                        Recipe ON RawMaterial.ID = Recipe.RawMaterialID
              WHERE     (Recipe.ProductID = @ProductID)
                   AND (Recipe.RawMaterialID = @RM_ID)
                   AND (Recipe.GroupID = @GroupID)
         SELECT     @SumQuantity = SUM(Recipe.Quantity)
         FROM     Recipe
         WHERE     (Recipe.ProductID = @ProductID)
              AND (Recipe.GroupID = @GroupID)
         SELECT     @SumRMC = (@SumCurPrice + @SumOldPrice) / @SumQuantity
         SELECT     @PTotalCost = (Product.Packing + Product.Overhead + Product.Others),
                   @PDPRate = Product.DPRate
         FROM     Product
         WHERE     (Product.ID = @ProductID) AND (Product.GroupID = @GroupID)
         SELECT     @PTotalCost = @PTotalCost + @SumRMC
         SELECT     @Result = (@PDPRate - @PTotalCost) / @PDPRate
         -- Return the result of the function
         RETURN @Result
    END
    END
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_RMCostImplication]') AND type in (N'P', N'PC'))
    BEGIN
    EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[sp_RMCostImplication]
         @GroupID int = 1,
         @RM_ID int = 1
    AS
    BEGIN
         -- SET NOCOUNT ON added to prevent extra result sets from
         -- interfering with SELECT statements.
         SET NOCOUNT ON;
         -- Insert statements for procedure here
         SELECT Product.Name, Product.DPRate, RawMaterial.Name AS RMName,
              RawMaterial.CurPrice,
              dbo.CalcGM(@GroupID, Product.ID, @RM_ID, 0)*100 AS CurGM,
              RawMaterial.OldPrice,
              dbo.CalcGM(@GroupID, Product.ID, @RM_ID, 1)*100 AS OldGM
         FROM Product INNER JOIN
              Recipe ON Product.ID = Recipe.ProductID INNER JOIN
              RawMaterial ON Recipe.RawMaterialID = RawMaterial.ID
         WHERE (Product.GroupID = @GroupID) AND (RawMaterial.ID = @RM_ID)
         ORDER BY Product.Name
    END
    END
    GO
    IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Product_GroupID]') AND parent_object_id = OBJECT_ID(N'[dbo].[Product]'))
    ALTER TABLE [dbo].[Product] WITH CHECK ADD CONSTRAINT [FK_Product_GroupID] FOREIGN KEY([GroupID])
    REFERENCES [dbo].[CostGroup] ([ID])
    GO
    ALTER TABLE [dbo].[Product] CHECK CONSTRAINT [FK_Product_GroupID]
    GO
    IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_RawMaterial_GroupID]') AND parent_object_id = OBJECT_ID(N'[dbo].[RawMaterial]'))
    ALTER TABLE [dbo].[RawMaterial] WITH CHECK ADD CONSTRAINT [FK_RawMaterial_GroupID] FOREIGN KEY([GroupID])
    REFERENCES [dbo].[CostGroup] ([ID])
    GO
    ALTER TABLE [dbo].[RawMaterial] CHECK CONSTRAINT [FK_RawMaterial_GroupID]
    GO
    IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Recipe_GroupID_ProductID]') AND parent_object_id = OBJECT_ID(N'[dbo].[Recipe]'))
    ALTER TABLE [dbo].[Recipe] WITH CHECK ADD CONSTRAINT [FK_Recipe_GroupID_ProductID] FOREIGN KEY([GroupID], [ProductID])
    REFERENCES [dbo].[Product] ([GroupID], [ID])
    GO
    ALTER TABLE [dbo].[Recipe] CHECK CONSTRAINT [FK_Recipe_GroupID_ProductID]
    GO
    IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Recipe_GroupID_RawMaterialID]') AND parent_object_id = OBJECT_ID(N'[dbo].[Recipe]'))
    ALTER TABLE [dbo].[Recipe] WITH CHECK ADD CONSTRAINT [FK_Recipe_GroupID_RawMaterialID] FOREIGN KEY([GroupID], [RawMaterialID])
    REFERENCES [dbo].[RawMaterial] ([GroupID], [ID])
    GO
    ALTER TABLE [dbo].[Recipe] CHECK CONSTRAINT [FK_Recipe_GroupID_RawMaterialID]
    Edited by: yogeshyl on Jul 28, 2009 4:50 PM

    Dear yogeshyl!
    OK, Let's try this step by step. I assume that you want to use Oracle in a version above 9i R2.
    -- Please change the size x to a value that fits your needs. Every tablespace needs a datafile.
    -- Please change <path_and_filename>.dbf to something like C:\oracle\oradata\ORCL\primary01.dbf.
    CREATE TABLESPACE primary
    DATAFILE '<path_and_filename>.dbf' SIZE x M;
    CREATE USER object_owner
    IDENTIFIED BY password
    DEFAULT TABLESPACE primary
    TEMPORARY TABLESPACE temp
    QUOTA unlimited ON primary;
    DROP TABLE object_owner.auditlog;
    CREATE TABLE object_owner.auditlog
    GroupID           NUMBER NOT NULL,
    ID                NUMBER NOT NULL CONSTRAINT pk_auditlog_id PRIMARY KEY,
    table_name        VARCHAR2(25) NOT NULL,
    field_name        VARCHAR2(25) NOT NULL,
    field_type        VARCHAR2(25) NULL,
    old_value         VARCHAR2(4000) NOT NULL,
    new_value         VARCHAR2(4000) NOT NULL,
    changed_on        TIMESTAMP NOT NULL,
    changed_by        NUMBER NOT NULL
    DROP TABLE object_owner.userrights;
    CREATE TABLE object_owner.userrights
    UserID       NUMBER NULL CONSTRAINT pk_userrights_userid PRIMARY KEY,
    MenuName     VARCHAR2(25),
    IsEnabled    NUMBER
    DROP TABLE object_owner.grademaster;
    CREATE TABLE object_owner.grademaster
    ID          NUMBER NULL CONSTRAINT pk_grademaster_id PRIMARY KEY,
    Name        VARCHAR2(25),
    Description VARCHAR2(25),
    source      NUMBER,
    destination NUMBER
    DROP TABLE object_owner.costgroup;
    CREATE TABLE object_owner.costgroup(
    ID          NUMBER NOT NULL CONSTRAINT pk_costgroup_id PRIMARY KEY,
    Name        VARCHAR2(25) NOT NULL
    DROP TABLE object_owner.masterid;
    CREATE TABLE object_owner.masterid
    TableID     NUMBER NOT NULL CONSTRAINT pk_masterid_table_id PRIMARY KEY,
    TableName   VARCHAR2(25) NOT NULL,
    NextID      NUMBER DEFAULT ((1))
    DROP TABLE object_owner.user_list;
    CREATE TABLE object_owner.userlist
    ID       NUMBER NOT NULL CONSTRAINT pk_userlist_id PRIMARY KEY,
    Name     VARCHAR2(25) NOT NULL,
    Password VARCHAR2(25) NOT NULL,
    FullName VARCHAR2(25)
    DROP TABLE object_owner.product;
    CREATE TABLE dbo.Product
    GroupID        NUMBER NOT NULL,
    ID             NUMBER NOT NULL,
    Name           VARCHAR2(50) NOT NULL,
    GrossMargin    NUMBER DEFAULT ((0)),
    RMC            NUMBER DEFAULT ((0)),
    Packing        NUMBER DEFAULT ((0)),
    Overhead       NUMBER DEFAULT ((0)),
    Others         NUMBER DEFAULT ((0)),
    TotalCost      NUMBER DEFAULT ((0)),
    DPRate         NUMBER DEFAULT ((0)),
    CreatedOn      DATE DEFAULT SYSDATE,
    CreatedBy      NUMBER DEFAULT ((1)),
    UpdatedOn      DATE DEFAULT SYSDATE,
    UpdatedBy      NUMBER DEFAULT ((1)),
    CONSTRAINT pk_product_groupid_id PRIMARY KEY (id, groupid);
    DROP TABLE object_owner.rawmaterial;
    CREATE TABLE object_owner.rawmaterial(
    GroupID NUMBER NOT NULL,
    ID        NUMBER NOT NULL,
    Name      VARCHAR2(50) NOT NULL,
    CurPrice  NUMBER,
    OldPrice  NUMBER,
    CreatedOn DATE,
    CreatedBy NUMBER,
    UpdatedOn DATE,
    UpdatedBy NUMBER,
    CONSTRAINT pk_rawmaterial_groupid_id PRIMARY KEY (groupid, id)
    DROP TABLE object_owner.recipe;
    CREATE TABLE object_owner.recipe
    GroupID NUMBER NOT NULL,
    ID            NUMBER NOT NULL,
    WEFDate       DATE NOT NULL,
    ProductID     NUMBER NOT NULL,
    RawMaterialID NUMBER NOT NULL,
    Seq           NUMBER NOT NULL,
    Quantity      NUMBER NOT NULL,
    RMCost        NUMBER NOT NULL,
    CreatedOn     DATE,
    CreatedBy     NUMBER,
    UpdatedOn     DATE,
    UpdatedBy     NUMBER,
    CONSTRAINT pk_r_gid_pid_rawmaterial_id PRIMARY KEY (GroupID, Seq, productid, rawmaterialID)
    CREATE OR REPLACE FUNCTION object_owner.to_index(p_string_to_index IN VARCHAR2) RETURN VARCHAR2
    IS
    l_temp VARCHAR2(1024);
    l_ivar   VARCHAR2(1024);
    l_tmps VARCHAR2(1);
    BEGIN
      l_ivar := UPPER(p_string_to_index);
      FOR i IN 1..LENGTH(p_string_to_index) LOOP
        l_tmps := SUBSTR(l_ivar, i, 1);
        IF ((ASCII(l_tmps) BETWEEN 48 AND 57) OR (ASCII(l_tmps) BETWEEN 65 AND 90)) THEN
          l_temp := l_temp || l_tmps;
        END IF;
    END LOOP;
      RETURN l_temp;
    END;
    ALTER TABLE object_owner.product
    DROP CONSTRAINT fk_product_groupid;
    ALTER TABLE object_owner.product
    ADD CONSTRAINT fk_product_groupid FOREIGN KEY (groupid)
    REFERENCES object_owner.costgroup(id);
    ALTER TABLE object_owner.rawmaterial
    DROP CONSTRAINT fk_rawmaterial_groupid;
    ALTER TABLE object_owner.rawmaterial
    ADD CONSTRAINT fk_rawmaterial_groupid FOREIGN KEY (groupid)
    REFERENCES object_owner.costgroup(id);
    ALTER TABLE object_owner.recipe
    DROP CONSTRAINT fk_recipe_groupid_productid ;
    ALTER TABLE object_owner.recipe
    ADD CONSTRAINT fk_recipe_groupid_productid FOREIGN KEY (groupid, productid)
    REFERENCES object_owner.product(groupid, id);
    ALTER TABLE object_owner.recipe
    DROP CONSTRAINT fk_recipe_groupid_rmatid;
    ALTER TABLE object_owner.recipe
    ADD CONSTRAINT fk_recipe_groupid_rmatid FOREIGN KEY (groupid, rawmaterialid)
    REFERENCES object_owner.rawmaterial (groupid, id);Yours sincerely
    Florian W.
    Edited by: Florian W. on 28.07.2009 13:22
    Edited by: Florian W. on 28.07.2009 13:29
    Edited by: Florian W. on 28.07.2009 13:40
    Edited by: Florian W. on 28.07.2009 13:58
    Edited by: Florian W. on 28.07.2009 14:10
    Edited by: Florian W. on 28.07.2009 14:21

  • How to connect to SQL Server through Script Task?

    Experts,
    I want to do bulk copy from one database to another database (which is on another different box).
    I was trying to follow below link,
    https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.bulkcopytimeout(v=vs.110).aspx
    but cannot connect to the source neither to target database.
    Can somebody help me with the sample connection string example and also via using existing connection manager?
    Thank You
    Regards,
    gk1393
    Please do let us know your feedback. Thank You - KG, MCTS

    I even tried with your VB code but still package is failing, here is the error message:-
    Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to class type 'System.Data.SqlClient.SqlConnection'.
    Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
       at ST_635f3bd1504c4d4c89a902eff277e13c.vbproj.ScriptMain.Main()
       --- End of inner exception stack trace ---
       at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
       at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
    Please do let us know your feedback. Thank You - KG, MCTS

  • C# application to execute both oracle and sql server script files.

    Hi All,
    I am suppose to develop an application using c# which can execute oracle script files as well as sql server script files based on some user's choice. 
    Both the script files(oracle/sql server) contains scripts to create tables, create views and create functions.
    What is the best way to do this and which existing c# functions should is use.
    Thanks in advance.

    I am suppose to develop an application using c# which can execute oracle script files as well as sql server script files based on some user's choice. 
    You can use SQL Plus for Oracle. You can have a C# program that issues commands  for  scripts for table, views, triggers  creation and the whole 10 yards to SQL Plus,
    http://docs.oracle.com/cd/B19306_01/server.102/b14357/qstart.htm
    https://www.google.com/#q=sql+plus
    I started writing a program to use SQL Plus to run the scripts, but cI ame to the conclusion that it was a waste of my time.
    A tool called OSM, an Oracle, tool gives a list of script files that need to be run do to a change in a script file based on file timestamp. You can copy the list doing a copy/past operation and drop it into SQL Plus's Command line, and SQL Plus runs the
    scripts.
    For MS SQL Server, you have this, which you can run from a C# program too.
    http://www.webfactory-world.de/wfknowledgebase/wfknowledgebase_wf3.3/Content/AdditionalWindowsSettings/Tutorials/UpdatingSQLDBFromCommandLine.htm
    I would consider using the above from a C# program a waste of time too.
    I look at it this way. If the user doesn't have database admin experience and know how to use DB admin tools, then they have no business doing anything with a database - period.
    BTW, the Invoke statement in VB or C# will run SQL Plus or SQL Server command line tool.

  • How to attach .mdf file to sql server 2008 EXPRESS

    I have .mdf files created using SQL SERVER management studio 2012 in another computer and wish to attach the same to SQL SERVER 2008 EXPRESS in another computer. How should I do so? I tried this method :How
    to: Attach a Database File to SQL Server Express but then it shows an error that the database cannot be created due to compatibility issues.
    Msg 948: The database xyz cannot be opened because it is version 706. This server supports version 655 and earlier. A downward path is not supported..
    Any help??

    I have .mdf files created using SQL SERVER management studio 2012 in another computer and wish to attach the same to SQL SERVER 2008 EXPRESS in another computer. How should I do so? I tried this method :How
    to: Attach a Database File to SQL Server Express but then it shows an error that the database cannot be created due to compatibility issues.
    Msg 948: The database xyz cannot be opened because it is version 706. This server supports version 655 and earlier. A downward path is not supported..
    Any help??
    You are trying to attach SQL Server 2012  database files to SQL Server 2008 R2 which is not allowed, you either need to upgrade your SQL Server 2008 to 2012 or alternatively you can generate all scripts from SQL Server 2012 and execute it in SQL Server
    2008 R2.
    You can refer below link to how to generate script.
    http://blog.sqlauthority.com/2012/07/18/sql-server-generate-script-for-schema-and-data-sql-in-sixty-seconds-021-video/
    Please mark solved if I've answered your question, vote for it as helpful to help other users find a solution quicker
    Praveen Dsa | MCITP - Database Administrator 2008 |
    My Blog | My Page

  • Issues using Oracle SQL server Developer migration work bench

    Hi all,
    We are trying to migrate the application databases from SQL server 2000 to Oracle 10g using Oracle SQL Developer 1.2.1.32.13:
    Following is the list of issues that we faced while trying out this migration on dev environment.
    1. The data migration was successful for only around 90 tables out of the total 166 tables present. No error message was logged for the rest of the tables but still it was completed.
    2. Some of the tables which had got the data inserted did not have the full data. Only some of the rows were inserted for these tables. Error message was logged only for few of the rows and not all.
    3. Few error messages were logged which said problems about “Inserting ' ' into column <tablename>.<columnname>”. There was no such constraint in the target database that the particular column can not be null or can not have only a space. Please check the logs for the same error messages.
    4. The status box at the end of migration had shown only 3 errors.
    5. The total data for migration was around 500MB. The time taken for migration was around 75 minutes. Are there any optimization techniques that will improve the performance?
    Please note that there were no Foreign Key references for the source schema or target schema.
    Any pointers/info/resolutions related to above mentioned issues will be much useful for us.
    Thanks,

    Hi Adam,
    There are 2 sets of scripts created for you.
    1) For SQL Servers BCP to dump out the data to dat files
    2) For Oracles SQL*Loader to load the dat files
    You run the SQL Server BCP scripts on the machine with SQL Server.
    The dat files will be dumped out on that server.
    You can then move the dat files to your Oracle server.
    Then run the Oracle SQL*Loader scripts to load the dat files into Oracle.
    Give it a go and follow the doc and viewlets.
    Your Questions:
    So the datadump from the source location would be saved on my local disk?it will be saved on the same machine you run the bcp scripts from. Usually the same machine SQL Server is on, because you require SQL Server BCP tool.
    So once it is migrated to the destination database will that dump be created automatically? Or do I need to modify the script to take care of this?I dont know what you mean by this, hopefully above clears things up.
    The only modifications you need to make to the scripts are adding in the databasename username password servername. These are outlined in the scripts themselves. I would want to do something fancy like dump the dat files to a different directory, then you can modify the scripts, but you should understand what they do first.
    Most people would have 500MB of space on their discs , so I can see the problem creating these dat files . The same goes for your 30 GB database.
    I hope this helps, but as always you wont get a good idea of how it works until you give it a go.
    Regards,
    Dermot.

  • Recreating SQL Server Tables on Oracle

    Hello,
    I need to recreate several SQL Server tables in Oracle and am trying to figure out if there is an easier way to do it other than manually recreating them.
    I have the SQL Server table scripts, and I have data load xls files that also contain the column names. I use TOAD for Oracle to do my database management, but there is currently no way to autmoatically create a table based on an external file.
    Does anyone have any suggestions?
    Thanks,
    Christine

    Manually re-creating these SQL Server tables for Oracle is exactly the right thing to do.
    SQL Server != Oracle
    In other words, there are numerous differences. You need to look at each table and decide on the type of table (hash table, index organised table, partitioned tables), whether to cluster tables, the types of indexes to use, the data types for the columns to use (Oracle does not have boolean or auto incrementing data types). Oracle supports LONG, RAW, CLOB and BLOB for dealing with different types of binary and large data structures. LONG for example should not be used anymore. There are also specialised data types like BFILE. One can also define your own SQL data types.
    You will only be doing yourself a favour, and the final database application, by going through the learning curve and manually converting each and every table. And no, it is not a huge task either. It sounds a lot more daunting that what it really is.

  • PeopleSoft - Backup and Restore scripts for PeopleSoft implementation using MS-SQL 2012?

    I am working for a county government as a consultant for PeopleSoft using SQL Server. When they restore a DEV instance from PROD, they have to manually stop the web server, app server and batch server, then they do the restore. Afterward they have to change
    all references to PROD in the cloned DEV instance. Everything is done manually and takes a couple of hours.
    Can anyone point me to scripts for PeopleSoft restores that automate bringing down/up the web, app and batch servers and all the other tasks so they don't have to be done manually?
    Life is hard, but it's harder when you're stupid! John 'Duke' Wayne

    This question should be posted on PeopleSoft support forum. That being said, a quick search on the internet will provide helpful links like below: http://www.erpassociates.com/peoplesoft-corner-wiki/peoplesoft-administration/cloning-a-peoplesoft-database.html
    Satish Kartan www.sqlfood.com

  • Error While executing a SSIS package which contains a script task through SQL Server Agent job

    Hi,
    I have a SQL Server 2012 SSIS package with a script task along with other tasks [data flow, execute sql tasks ]. When I manually executed the job through BIDS, its completed successfully. 
    Then I have automated the execution of the package through SQL Server Agent Job. But when I executed the package through SQL Agent job, it runs successfully for all the tasks except script task. When it comes to execute the Script Task, it is getting failed
    with the below error message.
    "Error: 2012-08-29 12:45:14.67
       Code: 0x00000001
       Source: Script Task 
       Description: Exception has been thrown by the target of an invocation.
    End Error
    DTExec: The package execution returned DTSER_FAILURE (1).
    Started:  12:45:10 PM
    Finished: 12:45:14 PM
    Elapsed:  4.353 seconds
    I have installed the SSIS on the 64-bit environment and SSIS service is running. Also I tried to run the job through 32 bit [job option] but I am getting the above error in all cases.
    Any help will be greatly appreaciated !
    Thanks,
    Navin
    - naveen.reddy

    Hi Arthur,
    My script task access the excel files in a network share, refresh them all and save them. When I execute the ETL manually or thru DTEXEC, it is executing successfully. I am facing the issue when I am executing thru SQL Agent Job only. Logging also showing
    the same error.
    "Error: 2012-08-23 12:45:14.67
       Code: 0x00000001
       Source: Script Task 
       Description: Exception has been thrown by the target of an invocation.
    End Error
    DTExec: The package execution returned DTSER_FAILURE (1).
    Started:  12:45:10 PM
    Finished: 12:45:14 PM
    Elapsed:  4.353 seconds
    - naveen.reddy

  • Msg 8631 Internal error: Server stack limit has been reached on SQL Server 2012 from T-SQL script that runs on SQL Server 2008 R2

    I have an Script mostly that is generated by SSMS which works with-out issue on SQL Server 2008, but when I attempt to run it on a new fresh install of SQL Server 2012 I get an Msg 8631. Internal error: Server stack limit has been reached. Please look for
    potentially deep nesting in your query, and try to simplify it.
    The script itself doesn't seem to be all that deep or nested.  The script is large 2600 lines and when I remove the bulk of the 2600 lines, it does run on SQL Server 2012.  I'm just really baffled why something that SQL Server generated with very
    few additions/changes AND that WORKS without issue in SQL Server 2008 R2 would suddenly be invalid in SQL Server 2012
    I need to know why my script which is working great on our current SQL Server 2008 R2 servers suddenly fails and won't run on an new SQL Server 2012 server.  This script is used to create 'bulk' Replications on a large number of DBs saving a tremendous
    amount of our time doing it the manual way.
    Below is an 'condensed' version of the script which fails.  I have removed around 2550 lines of specific sp_addarticle statements which are mostly just copy and pasted from what SQL Management Studio 'scripted' for me went I when through the Replication
    Wizard and told it to save to script.
    declare @dbname varchar(MAX), @SQL nvarchar(MAX)
    declare c_dblist cursor for
    select name from sys.databases WHERE name like 'dbone[_]%' order by name;
    open c_dblist
    fetch next from c_dblist into @dbname
    while @@fetch_status = 0
    begin
    print @dbname
    SET @SQL = 'DECLARE @dbname NVARCHAR(MAX); SET @dbname = ''' + @dbname + ''';
    use ['+@dbname+']
    exec sp_replicationdboption @dbname = N'''+@dbname+''', @optname = N''publish'', @value = N''true''
    use ['+@dbname+']
    exec ['+@dbname+'].sys.sp_addlogreader_agent @job_login = N''DOMAIN\DBServiceAccount'', @job_password = N''secret'', @publisher_security_mode = 1, @job_name = null
    -- Adding the transactional publication
    use ['+@dbname+']
    exec sp_addpublication @publication = N'''+@dbname+' Replication'', @description = N''Transactional publication of database
    '''''+@dbname+''''' from Publisher ''''MSSQLSRV\INSTANCE''''.'', @sync_method = N''concurrent'', @retention = 0, @allow_push = N''true'', @allow_pull = N''true'', @allow_anonymous = N''false'', @enabled_for_internet
    = N''false'', @snapshot_in_defaultfolder = N''true'', @compress_snapshot = N''false'', @ftp_port = 21, @allow_subscription_copy = N''false'', @add_to_active_directory = N''false'', @repl_freq = N''continuous'', @status = N''active'', @independent_agent = N''true'',
    @immediate_sync = N''true'', @allow_sync_tran = N''false'', @allow_queued_tran = N''false'', @allow_dts = N''false'', @replicate_ddl = 1, @allow_initialize_from_backup = N''true'', @enabled_for_p2p = N''false'', @enabled_for_het_sub = N''false''
    exec sp_addpublication_snapshot @publication = N'''+@dbname+' Replication'', @frequency_type = 1, @frequency_interval = 1, @frequency_relative_interval = 1, @frequency_recurrence_factor = 0, @frequency_subday = 8,
    @frequency_subday_interval = 1, @active_start_time_of_day = 0, @active_end_time_of_day = 235959, @active_start_date = 0, @active_end_date = 0, @job_login = N''DOMAIN\DBServiceAccount'', @job_password = N''secret'', @publisher_security_mode = 1
    -- There are around 2400 lines roughly the same as this only difference is the tablename repeated below this one
    use ['+@dbname+']
    exec sp_addarticle @publication = N'''+@dbname+' Replication'', @article = N''TABLE_ONE'', @source_owner = N''dbo'', @source_object = N''TABLE_ONE'', @type = N''logbased'', @description = null, @creation_script =
    null, @pre_creation_cmd = N''drop'', @schema_option = 0x000000000803509F, @identityrangemanagementoption = N''manual'', @destination_table = N''TABLE_ONE'', @destination_owner = N''dbo'', @vertical_partition = N''false'', @ins_cmd = N''CALL sp_MSins_dboTABLE_ONE'',
    @del_cmd = N''CALL sp_MSdel_dboTABLE_ONE'', @upd_cmd = N''SCALL sp_MSupd_dboTABLE_ONE''
    EXEC sp_executesql @SQL
    SET @dbname = REPLACE(@dbname, 'dbone_', 'dbtwo_');
    print @dbname
    SET @SQL = 'DECLARE @dbname NVARCHAR(MAX); SET @dbname = ''' + @dbname + ''';
    use ['+@dbname+']
    exec sp_replicationdboption @dbname = N'''+@dbname+''', @optname = N''publish'', @value = N''true''
    use ['+@dbname+']
    exec ['+@dbname+'].sys.sp_addlogreader_agent @job_login = N''DOMAIN\DBServiceAccount'', @job_password = N''secret'', @publisher_security_mode = 1, @job_name = null
    -- Adding the transactional publication
    use ['+@dbname+']
    exec sp_addpublication @publication = N'''+@dbname+' Replication'', @description = N''Transactional publication of database
    '''''+@dbname+''''' from Publisher ''''MSSQLSRV\INSTANCE''''.'', @sync_method = N''concurrent'', @retention = 0, @allow_push = N''true'', @allow_pull = N''true'', @allow_anonymous = N''false'', @enabled_for_internet
    = N''false'', @snapshot_in_defaultfolder = N''true'', @compress_snapshot = N''false'', @ftp_port = 21, @allow_subscription_copy = N''false'', @add_to_active_directory = N''false'', @repl_freq = N''continuous'', @status = N''active'', @independent_agent = N''true'',
    @immediate_sync = N''true'', @allow_sync_tran = N''false'', @allow_queued_tran = N''false'', @allow_dts = N''false'', @replicate_ddl = 1, @allow_initialize_from_backup = N''true'', @enabled_for_p2p = N''false'', @enabled_for_het_sub = N''false''
    exec sp_addpublication_snapshot @publication = N'''+@dbname+' Replication'', @frequency_type = 1, @frequency_interval = 1, @frequency_relative_interval = 1, @frequency_recurrence_factor = 0, @frequency_subday = 8,
    @frequency_subday_interval = 1, @active_start_time_of_day = 0, @active_end_time_of_day = 235959, @active_start_date = 0, @active_end_date = 0, @job_login = N''DOMAIN\DBServiceAccount'', @job_password = N''secret'', @publisher_security_mode = 1
    -- There are around 140 lines roughly the same as this only difference is the tablename repeated below this one
    use ['+@dbname+']
    exec sp_addarticle @publication = N'''+@dbname+' Replication'', @article = N''DB_TWO_TABLE_ONE'', @source_owner = N''dbo'', @source_object = N''DB_TWO_TABLE_ONE'', @type = N''logbased'', @description = null, @creation_script
    = null, @pre_creation_cmd = N''drop'', @schema_option = 0x000000000803509D, @identityrangemanagementoption = N''manual'', @destination_table = N''DB_TWO_TABLE_ONE'', @destination_owner = N''dbo'', @vertical_partition = N''false''
    EXEC sp_executesql @SQL
    fetch next from c_dblist into @dbname
    end
    close c_dblist
    deallocate c_dblist
    George P Botuwell, Programmer

    Hi George,
    Thank you for your question. 
    I am trying to involve someone more familiar with this topic for a further look at this issue. Sometime delay might be expected from the job transferring. Your patience is greatly appreciated. 
    Thank you for your understanding and support.
    If you have any feedback on our support, please click
    here.
    Allen Li
    TechNet Community Support

  • Is there any simple way to run same sql script on multiple remote sql server databases at once?

    i am using sql server 2005. our company has many branches. each branch is located in different country. so when i update database in any country over the VPN connection then i need to update db in another country one by one over the vpn connection. it
    is very tire some job....so i was think that there could be any easy trick to update multiple db in different country easily. so am developing a store procedure which will connect each DB in different database one after one over the vpn and read script from
    sql file and execute the script in remote db over vpn. so please have look at my script and tell me how to do it. please do not advise me to use any 3rd party.
    here is a table structure where i will put all my remote db details.
    CREATE TABLE [dbo].[DBDetails]
    [ServerName] [varchar](max)     NULL,
    [DBName] [varchar](max)         NULL,
    [UserID] [varchar](max)         NULL,
    [Password] [varchar](max)       NULL,
    [CountryCode] [varchar](2)      NULL
    SET NOCOUNT ON
    DECLARE DB CURSOR FOR SELECT ServerName,DBName,UserID,Password,CountryCode FROM    DBDetails
    OPEN DB
    DECLARE @ServerName     varchar(MAX)
    DECLARE @DBName         varchar(MAX)
    DECLARE @UserID         varchar(MAX)
    DECLARE @Password       varchar(MAX)
    DECLARE @CountryCode    varchar(2)
    FETCH NEXT FROM DB INTO @ServerName,@DBName,@UserID,@Password,@CountryCode
    WHILE @@FETCH_STATUS = 0
    BEGIN
    -- here i need some help for opening db connection and read sql file and execute  the statement
    -- Please help here
    FETCH NEXT FROM DB INTO @ServerName,@DBName,@UserID,@Password,@CountryCode
     END
     CLOSE DB
     DEALLOCATE DB
    thanks

    One way: set them as jobs and assign the same schedule or start them from a stored procedure:
    http://www.sqlusa.com/bestpractices2005/startjobfromstoredproc/
    Note: when you start a job from a stored procedure, control proceeds to the next statement, there is no wait for the job to finish.
    Kalman Toth SQL SERVER 2012 & BI TRAINING
    New Book: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2012

  • Error while executing SSIS package which contains Script component through SQL Server Agent Job

    Hello All,
    I have written one SSIS 2012 package which is fetching records from CSV and put it into staging DB and from staging DB , using SSIS script component task, I am inserting data into Dynamics CRM. So far it is working fine when
    I manually execute SSIS package.
    but when I run the SSIS package using SQL server agent job, I encounter below error. After seeing below error at step "Insert TLM Headers Script Component " I understand that it is failing at script component which I have used in SSIS package,
    but I am not sure what is the cause behind that? please advise.
    Error:
    Executed as user: domain\user account. Microsoft (R) SQL Server Execute Package Utility  Version 11.0.5556.0 for 64-bit  Copyright (C) Microsoft Corporation. All rights reserved.    Started:  1:21:41 PM  Error: 2015-02-25
    13:21:45.94     Code: 0xC0047062     Source: Insert TLM Headers Script Component [205]     Description: System.ServiceModel.FaultException: The server was unable to process the request due to an internal
    error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to
    the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.    Server stack trace:      at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message
    reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)     at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)    
    at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)     at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage
    methodCall, ProxyOperationRuntime operation)     at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)    Exception rethrown at [0]:      at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.HandleUserException(Exception
    e)     at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ProcessInput(Int32 inputID, PipelineBuffer buffer)     at Microsoft.SqlServer.Dts.Pipeline.ManagedComponentHost.HostProcessInput(IDTSManagedComponentWrapper100
    wrapper, Int32 inputID, IDTSBuffer100 pDTSBuffer, IntPtr bufferWirePacket)  End Error  Error: 2015-02-25 13:21:45.94     Code: 0xC0047022     Source: Insert TLM Headers SSIS.Pipeline    
    Description: SSIS Error Code DTS_E_PROCESSINPUTFAILED.  The ProcessInput method on component "Script Component" (205) failed with error code 0x80131501 while processing input "Input 0" (215). The identified component returned an error
    from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running.  There may be error messages posted before this with more information about the failure.  End Error 
    DTExec: The package execution returned DTSER_FAILURE (1).  Started:  1:21:41 PM  Finished: 1:21:45 PM  Elapsed:  4.009 seconds.  The package execution failed.  The step failed.
    Thanks
    Pankaj

    domain\user account has not proper rights
    That being said, often SSIS jobs require a proxy to be runnable and this is how you make one up
    http://www.mssqltips.com/sqlservertip/2163/running-a-ssis-package-from-sql-server-agent-using-a-proxy-account/
    Arthur
    MyBlog
    Twitter

  • Update Script Issue in SQL server 2008 r2

    please see my below script whenever i run this script i got below error
    update Scmdb..StockAge set Age1=SUM(a.gr_lin_acceptedqty) 
    from scmdb..gr_lin_details a 
    where DATEDIFF(day,a.gr_lin_fadate,'2014-02-02')<90 
    and ItemCode=a.gr_lin_itemcode 
    and VarCode=a.gr_lin_itemvariant
    Error : An aggregate may not appear in the set list of an UPDATE statement.

    Hi,
    Please check this
    update Scmdb..StockAge set Age1=(SELECT SUM(a.gr_lin_acceptedqty)
    from scmdb..gr_lin_details a
    where DATEDIFF(day,a.gr_lin_fadate,'2014-02-02')<90
    and ItemCode=a.gr_lin_itemcode
    and VarCode=a.gr_lin_itemvariant)
    I hope this is helpful.
    Please Mark it as Answered if it answered your question
    OR mark it as Helpful if it help you to solve your problem
    Elmozamil Elamir Hamid
    MCSE Data Platform
    MCITP: SQL Server 2008 Administration/Development
    MCSA SQL Server 2012
    MCTS: SQL Server Administration/Development
    MyBlog

  • Generate Scripts in SQL Server 2008 R2 producing Error "Item has already been added.:

    I am trying to run a Generate Scripts Task on a Database to generate a script for every object in the DB including tables, SPs, UDFs, FKs, PKs, with the settings for Schema Only, Script Drop and Create, Script "if not Exists", use database,
    and Object level permissions. 
    I have used generate scripts before to generate this database about 5 months ago and every thing worked fine. 
    Today I first tried to generate it out on a server where I only have "db_Owner" for several databases.  This failed with the error.
    Microsoft.SqlServer.Management.Smo.FailedOperationException: Discover dependencies failed. ---> System.ArgumentException: Item has already been added. Key in dictionary: 'Server[@Name='DLINHD007557\SQL_2008R2_64']/Database[@Name='VFS_ProcurementTracking']/UnresolvedEntity[@Name='prc_ContractFatInfo']' Key being added: 'Server[@Name='DLINHD007557\SQL_2008R2_64']/Database[@Name='VFS_ProcurementTracking']/UnresolvedEntity[@Name='prc_ContractFatInfo']' at System.Collections.SortedList.Add(Object key, Object value) at Microsoft.SqlServer.Management.Smo.DependencyTree..ctor(Urn[] urns, DependencyChainCollection dependencies, Boolean fParents, Server server)
    So I tried tto do this on a local version of the database where I have sa rights.  Same error.
    Can someone advise me on what is going on here and how do I fix it?
    Edward R. Joell MCSD MCDBA

    How do you generate the script via SMO?
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

Maybe you are looking for

  • How to enable email notification in OIM 11g

    Hello, I am currently working in a stock 11.1.1.3.0 environment, and am trying to enable email notifications when a user requests to be provisioned to AD. The default approver is Xelsysadm, and I have put my email address in this account's slot. Howe

  • Displaying a word file stored as BLOB in the database

    Post Author: Sathish K Sekar CA Forum: WebIntelligence Reporting Hi, Is it possible for us to display a word file which is stored as a BLOB object in  our database. We are using BO XIR2. Thanks in advance Sathish

  • Ribbon Custom Action - Timesheet Project Online 2013

    I'm trying to create a Custom Action for the timesheet form in Project Online 2013. In Visual Studio, when I try to add the Custom Action, I'm providing the following info: Where do you want to expose the custom action? Host Web Where is the custom a

  • How to create a special gl indicator

    hi, can any body help me out in creatin speaial gl indicator apart from SAP Standard with regards, jayaprkash

  • Exeception during execution error

    hi,    My XML file is read from Application into XI.I'm receiveing this error"<b></b>EXCEPTION DURING EXECUTION".I know this is related to MApping.I've checked my mapping and its working fine.I'm doing this scenario in BPM so will there be any proble