Showing posts with label message. Show all posts
Showing posts with label message. Show all posts

Wednesday, March 28, 2012

script to take backup of a database

Hi,

I am trying to create a script that takes backup of a sql database. The script is failing with message "backup failed with message..."

Option Explicit

Dim server

Dim backup

Set server = CreateObject("Microsoft.SQLServer.Management.SMO.Server")

Set backup = CreateObject("Microsoft.SQLServer.Management.SMO.Backup")

backup.Action = 0

backup.Database = "test_old"

backup.SqlBackup(server)

I think this is failing because i did not specify the backup file name. Can u please let me know how can i specify it?

Also it would be great if you can point me to some relevant documentation which shows how to use SMO with vb script.

Regards

Aseem Bansal

You can't use SMO with VBScript. (Well, you can, but you can't use it to communicate with anything but the default server on your local machine.)

Books Online has good examples how to backup a database.

|||

I do not have one in vbscript, but here is one in C#...

using System;

using System.Data;

using System.Collections;

using Microsoft.SqlServer.Management.Common;

using Microsoft.SqlServer.Management.Smo;

class Program

{

static void Main(string[] args)

{

BackupDeviceItem bdi =

new BackupDeviceItem("AdventureWorks.bak", DeviceType.File);

Backup bu = new Backup( );

bu.Database = "AdventureWorks";

bu.Devices.Add(bdi);

bu.Initialize = true;

// add percent complete and complete event handlers

bu.PercentComplete +=

new PercentCompleteEventHandler(Backup_PercentComplete);

bu.Complete +=new ServerMessageEventHandler(Backup_Complete);

Server server = new Server("localhost");

bu.SqlBackup(server);

Console.WriteLine(Environment.NewLine + "Press any key to continue.");

Console.ReadKey( );

}

protected static void Backup_PercentComplete(

object sender, PercentCompleteEventArgs e)

{

Console.WriteLine(e.Percent + "% processed.");

}

protected static void Backup_Complete(object sender, ServerMessageEventArgs e)

{

Console.WriteLine(Environment.NewLine + e.ToString( ));

}

}

|||

Can you do this in a windows form application please..? Seems like it doesn't work...I don't know.. If can please let me know..thank you...darshaka..



script to take backup of a database

Hi,

I am trying to create a script that takes backup of a sql database. The script is failing with message "backup failed with message..."

Option Explicit

Dim server

Dim backup

Set server = CreateObject("Microsoft.SQLServer.Management.SMO.Server")

Set backup = CreateObject("Microsoft.SQLServer.Management.SMO.Backup")

backup.Action = 0

backup.Database = "test_old"

backup.SqlBackup(server)

I think this is failing because i did not specify the backup file name. Can u please let me know how can i specify it?

Also it would be great if you can point me to some relevant documentation which shows how to use SMO with vb script.

Regards

Aseem Bansal

You can't use SMO with VBScript. (Well, you can, but you can't use it to communicate with anything but the default server on your local machine.)

Books Online has good examples how to backup a database.

|||

I do not have one in vbscript, but here is one in C#...

using System;

using System.Data;

using System.Collections;

using Microsoft.SqlServer.Management.Common;

using Microsoft.SqlServer.Management.Smo;

class Program

{

static void Main(string[] args)

{

BackupDeviceItem bdi =

new BackupDeviceItem("AdventureWorks.bak", DeviceType.File);

Backup bu = new Backup( );

bu.Database = "AdventureWorks";

bu.Devices.Add(bdi);

bu.Initialize = true;

// add percent complete and complete event handlers

bu.PercentComplete +=

new PercentCompleteEventHandler(Backup_PercentComplete);

bu.Complete +=new ServerMessageEventHandler(Backup_Complete);

Server server = new Server("localhost");

bu.SqlBackup(server);

Console.WriteLine(Environment.NewLine + "Press any key to continue.");

Console.ReadKey( );

}

protected static void Backup_PercentComplete(

object sender, PercentCompleteEventArgs e)

{

Console.WriteLine(e.Percent + "% processed.");

}

protected static void Backup_Complete(object sender, ServerMessageEventArgs e)

{

Console.WriteLine(Environment.NewLine + e.ToString( ));

}

}

|||

Can you do this in a windows form application please..? Seems like it doesn't work...I don't know.. If can please let me know..thank you...darshaka..



sql

Wednesday, March 21, 2012

Script task: Dts.Logging.Log

I am trying to understand the use-case of Dts.Logging.Log.

Following BOL, I see that I can use Dts.Log to send a custom log message to my log provider. The following example code produces an event called "User:ScriptTaskLogEntry", with the message "My custom message here".

Dim dataBytes(0) As Byte

Dts.Log("My custom message here", 0, dataBytes)

I would like to be able to produce my own custom event (lets call it "MyCustomEvent"), as well as a custom log message. I thought it would be possible via Dts.Logging.Log, which requires that I specify an event name, in addition to a log entry. However, when I place the following code in the script task, I do not get any logging whatsoever.

Dim dataBytes(0) As Byte

Dts.Logging.Log("MyCustomEvent", System.Environment.MachineName, System.Environment.UserName, "Custom Log", "", "", "My custom message here", Now, Now, 0, dataBytes)

Any thoughts?

Thanks!

The script task can't log custom message type. The problem is that custom log message needs to be declared by task in advance so that it appears in the Details tab of the Logging window.

Custom task (reusable separately packaged .NET or C++ code, that appears on toolbox just like any Microsoft task) can do it, but this functionality is not available in Script task.sql

Script Task scripts will not stop at breakpoints.

I can not debug any of my scripts. They execute just fine, but if I have a breakpoint set in the script code (in VSA), I get the message:

SQL server integration services script task has encountered a problem and needs to close. We are sorry for the inconvenience.

If you were in the middle of something, the information you were working on might be lost.

Debug Close

When I choose "Close" I get this:

sMicrosoft Visual Studio for Applications has lost the link to .

Your work will be exported to <<my Local Settings My Documents path>> when you quit the application.

OK

When I click "OK" my package executes normally, but no breakpoints will fire from that point on.

No need to post your message twice....

Script Tasks, not Script Components, correct?

One workaround is to use a MSGBOX().|||I was in the process of deleting my other post when you replied. I didn't want to post in a thread that had something marked as an answer. Yes, this is for script tasks. I certainly could use MsgBox() but that is hardly an answer to this problem. I could also write text out to a file, call a web service, insert a record into a table, etc. None of those things take the place of stepping through code. Is there a fix in the works for this issue? It really makes script tasks of limited use, or at least it makes them take much longer to develop.|||And you are following these steps?

http://technet.microsoft.com/en-us/library/ms140033.aspx|||With the exception of right-clicking (I was clicking in the margin to set the breakpoint), yes, that is exactly what I did.|||Do you have any SQL Server service packs applied?|||How would I tell?|||

JWardRogers wrote:

How would I tell?

In BIDS, go to Help->About and select SSIS. What is the version number reported there?|||9.00.1399.00|||That's the original.

Try grabbing the SQL Server Service Pack 2 and installing that. Many fixes are contained in SP1 and SP2 as well.|||

Phil Brammer wrote:

That's the original.

Try grabbing the SQL Server Service Pack 2 and installing that. Many fixes are contained in SP1 and SP2 as well.

But unfortunately not the fix for my problem. :-(

SP2 is installed and it is still behaving the same way.

Version is now 9.00.3042.00

|||

I'm still having the same problem...

|||XP? Vista?|||

Server 2003 version 5.2.3790 (service pack 1.0)

Hot Fix: KB931836

4GB RAM

|||

JWardRogers wrote:

Server 2003 version 5.2.3790 (service pack 1.0)

Hot Fix: KB931836

4GB RAM

Do you also develop on a local workstation? Have you tried breakpoints on that if so?

Script Task scripts will not stop at breakpoints.

I can not debug any of my scripts. They execute just fine, but if I have a breakpoint set in the script code (in VSA), I get the message:

SQL server integration services script task has encountered a problem and needs to close. We are sorry for the inconvenience.

If you were in the middle of something, the information you were working on might be lost.

Debug Close

When I choose "Close" I get this:

sMicrosoft Visual Studio for Applications has lost the link to .

Your work will be exported to <<my Local Settings My Documents path>> when you quit the application.

OK

When I click "OK" my package executes normally, but no breakpoints will fire from that point on.

No need to post your message twice....

Script Tasks, not Script Components, correct?

One workaround is to use a MSGBOX().|||I was in the process of deleting my other post when you replied. I didn't want to post in a thread that had something marked as an answer. Yes, this is for script tasks. I certainly could use MsgBox() but that is hardly an answer to this problem. I could also write text out to a file, call a web service, insert a record into a table, etc. None of those things take the place of stepping through code. Is there a fix in the works for this issue? It really makes script tasks of limited use, or at least it makes them take much longer to develop.|||And you are following these steps?

http://technet.microsoft.com/en-us/library/ms140033.aspx|||With the exception of right-clicking (I was clicking in the margin to set the breakpoint), yes, that is exactly what I did.|||Do you have any SQL Server service packs applied?|||How would I tell?|||

JWardRogers wrote:

How would I tell?

In BIDS, go to Help->About and select SSIS. What is the version number reported there?|||9.00.1399.00|||That's the original.

Try grabbing the SQL Server Service Pack 2 and installing that. Many fixes are contained in SP1 and SP2 as well.|||

Phil Brammer wrote:

That's the original.

Try grabbing the SQL Server Service Pack 2 and installing that. Many fixes are contained in SP1 and SP2 as well.

But unfortunately not the fix for my problem. :-(

SP2 is installed and it is still behaving the same way.

Version is now 9.00.3042.00

|||

I'm still having the same problem...

|||XP? Vista?|||

Server 2003 version 5.2.3790 (service pack 1.0)

Hot Fix: KB931836

4GB RAM

|||

JWardRogers wrote:

Server 2003 version 5.2.3790 (service pack 1.0)

Hot Fix: KB931836

4GB RAM

Do you also develop on a local workstation? Have you tried breakpoints on that if so?sql

Script Task scripts will not stop at breakpoints.

I can not debug any of my scripts. They execute just fine, but if I have a breakpoint set in the script code (in VSA), I get the message:

SQL server integration services script task has encountered a problem and needs to close. We are sorry for the inconvenience.

If you were in the middle of something, the information you were working on might be lost.

Debug Close

When I choose "Close" I get this:

sMicrosoft Visual Studio for Applications has lost the link to .

Your work will be exported to <<my Local Settings My Documents path>> when you quit the application.

OK

When I click "OK" my package executes normally, but no breakpoints will fire from that point on.

No need to post your message twice....

Script Tasks, not Script Components, correct?

One workaround is to use a MSGBOX().|||I was in the process of deleting my other post when you replied. I didn't want to post in a thread that had something marked as an answer. Yes, this is for script tasks. I certainly could use MsgBox() but that is hardly an answer to this problem. I could also write text out to a file, call a web service, insert a record into a table, etc. None of those things take the place of stepping through code. Is there a fix in the works for this issue? It really makes script tasks of limited use, or at least it makes them take much longer to develop.|||And you are following these steps?

http://technet.microsoft.com/en-us/library/ms140033.aspx|||With the exception of right-clicking (I was clicking in the margin to set the breakpoint), yes, that is exactly what I did.|||Do you have any SQL Server service packs applied?|||How would I tell?|||

JWardRogers wrote:

How would I tell?

In BIDS, go to Help->About and select SSIS. What is the version number reported there?|||9.00.1399.00|||That's the original.

Try grabbing the SQL Server Service Pack 2 and installing that. Many fixes are contained in SP1 and SP2 as well.|||

Phil Brammer wrote:

That's the original.

Try grabbing the SQL Server Service Pack 2 and installing that. Many fixes are contained in SP1 and SP2 as well.

But unfortunately not the fix for my problem. :-(

SP2 is installed and it is still behaving the same way.

Version is now 9.00.3042.00

|||

I'm still having the same problem...

|||XP? Vista?|||

Server 2003 version 5.2.3790 (service pack 1.0)

Hot Fix: KB931836

4GB RAM

|||

JWardRogers wrote:

Server 2003 version 5.2.3790 (service pack 1.0)

Hot Fix: KB931836

4GB RAM

Do you also develop on a local workstation? Have you tried breakpoints on that if so?

Script Task scripts will not stop at breakpoints.

I can not debug any of my scripts. They execute just fine, but if I have a breakpoint set in the script code (in VSA), I get the message:

SQL server integration services script task has encountered a problem and needs to close. We are sorry for the inconvenience.

If you were in the middle of something, the information you were working on might be lost.

Debug Close

When I choose "Close" I get this:

sMicrosoft Visual Studio for Applications has lost the link to .

Your work will be exported to <<my Local Settings My Documents path>> when you quit the application.

OK

When I click "OK" my package executes normally, but no breakpoints will fire from that point on.

No need to post your message twice....

Script Tasks, not Script Components, correct?

One workaround is to use a MSGBOX().|||I was in the process of deleting my other post when you replied. I didn't want to post in a thread that had something marked as an answer. Yes, this is for script tasks. I certainly could use MsgBox() but that is hardly an answer to this problem. I could also write text out to a file, call a web service, insert a record into a table, etc. None of those things take the place of stepping through code. Is there a fix in the works for this issue? It really makes script tasks of limited use, or at least it makes them take much longer to develop.|||And you are following these steps?

http://technet.microsoft.com/en-us/library/ms140033.aspx|||With the exception of right-clicking (I was clicking in the margin to set the breakpoint), yes, that is exactly what I did.|||Do you have any SQL Server service packs applied?|||How would I tell?|||

JWardRogers wrote:

How would I tell?

In BIDS, go to Help->About and select SSIS. What is the version number reported there?|||9.00.1399.00|||That's the original.

Try grabbing the SQL Server Service Pack 2 and installing that. Many fixes are contained in SP1 and SP2 as well.|||

Phil Brammer wrote:

That's the original.

Try grabbing the SQL Server Service Pack 2 and installing that. Many fixes are contained in SP1 and SP2 as well.

But unfortunately not the fix for my problem. :-(

SP2 is installed and it is still behaving the same way.

Version is now 9.00.3042.00

|||

I'm still having the same problem...

|||XP? Vista?|||

Server 2003 version 5.2.3790 (service pack 1.0)

Hot Fix: KB931836

4GB RAM

|||

JWardRogers wrote:

Server 2003 version 5.2.3790 (service pack 1.0)

Hot Fix: KB931836

4GB RAM

Do you also develop on a local workstation? Have you tried breakpoints on that if so?

Script Task scripts will not stop at breakpoints.

I can not debug any of my scripts. They execute just fine, but if I have a breakpoint set in the script code (in VSA), I get the message:

SQL server integration services script task has encountered a problem and needs to close. We are sorry for the inconvenience.

If you were in the middle of something, the information you were working on might be lost.

Debug Close

When I choose "Close" I get this:

sMicrosoft Visual Studio for Applications has lost the link to .

Your work will be exported to <<my Local Settings My Documents path>> when you quit the application.

OK

When I click "OK" my package executes normally, but no breakpoints will fire from that point on.

No need to post your message twice....

Script Tasks, not Script Components, correct?

One workaround is to use a MSGBOX().|||I was in the process of deleting my other post when you replied. I didn't want to post in a thread that had something marked as an answer. Yes, this is for script tasks. I certainly could use MsgBox() but that is hardly an answer to this problem. I could also write text out to a file, call a web service, insert a record into a table, etc. None of those things take the place of stepping through code. Is there a fix in the works for this issue? It really makes script tasks of limited use, or at least it makes them take much longer to develop.|||And you are following these steps?

http://technet.microsoft.com/en-us/library/ms140033.aspx|||With the exception of right-clicking (I was clicking in the margin to set the breakpoint), yes, that is exactly what I did.|||Do you have any SQL Server service packs applied?|||How would I tell?|||

JWardRogers wrote:

How would I tell?

In BIDS, go to Help->About and select SSIS. What is the version number reported there?|||9.00.1399.00|||That's the original.

Try grabbing the SQL Server Service Pack 2 and installing that. Many fixes are contained in SP1 and SP2 as well.|||

Phil Brammer wrote:

That's the original.

Try grabbing the SQL Server Service Pack 2 and installing that. Many fixes are contained in SP1 and SP2 as well.

But unfortunately not the fix for my problem. :-(

SP2 is installed and it is still behaving the same way.

Version is now 9.00.3042.00

|||

I'm still having the same problem...

|||XP? Vista?|||

Server 2003 version 5.2.3790 (service pack 1.0)

Hot Fix: KB931836

4GB RAM

|||

JWardRogers wrote:

Server 2003 version 5.2.3790 (service pack 1.0)

Hot Fix: KB931836

4GB RAM

Do you also develop on a local workstation? Have you tried breakpoints on that if so?

Tuesday, March 20, 2012

Script line number

When you get a server error message referring to a line number in a
script, is there an easy way to jump to the correct line? It's not
easy to count down in a big script or when there is a lot of white
space.

In WordPerfect we had a linenum macro that allowed you to enter the
line number and it would jump to the line using the same counting
method as the interpreter that generated the error message. Is there
something similar with TSQL, or another way?

Kerry"Kerry" <kerrytforums@.hotmail.com> wrote:
> When you get a server error message referring to a line number in a
> script, is there an easy way to jump to the correct line? It's not
> easy to count down in a big script or when there is a lot of white
> space.
> In WordPerfect we had a linenum macro that allowed you to enter the
> line number and it would jump to the line using the same counting
> method as the interpreter that generated the error message. Is there
> something similar with TSQL, or another way?
> Kerry

Kerry,

That will depend on your editor... most editors (including Query Analyzer
with SQL Server 2000, Notepad in WinXP, and Visual Studio) have a function
for jumping to a specific line number. In most editors I've worked with on
Windows, it's usually ctrl-G

Craig|||In Query Analyzer, you can double-click on the error message in the
result pane to jump to the source line in question.

--
Hope this helps.

Dan Guzman
SQL Server MVP

--------
SQL FAQ links (courtesy Neil Pike):

http://www.ntfaq.com/Articles/Index...epartmentID=800
http://www.sqlserverfaq.com
http://www.mssqlserver.com/faq
--------

"Kerry" <kerrytforums@.hotmail.com> wrote in message
news:6e61c2be.0311140759.25063405@.posting.google.c om...
> When you get a server error message referring to a line number in a
> script, is there an easy way to jump to the correct line? It's not
> easy to count down in a big script or when there is a lot of white
> space.
> In WordPerfect we had a linenum macro that allowed you to enter the
> line number and it would jump to the line using the same counting
> method as the interpreter that generated the error message. Is there
> something similar with TSQL, or another way?
> Kerry

Wednesday, March 7, 2012

Script Component failed validation and returned validation status "VS_ISBROKEN". Error

I have been running this package before (with no errors) but now I get this error message. Is it my enviroment that is broken? All my Script Compnents end up with this error code.

Error: 0xC0047062 at Data Flow Task, Script Component [53]: System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {A138CF39-2CAE-42C2-ADB3-022658D79F2F} failed with HRESULT: 0x80040154(Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))).

at Microsoft.VisualBasic.Vsa.VsaEngine.CreateEngine()

at Microsoft.VisualBasic.Vsa.VsaEngine.CheckEngine()

at Microsoft.VisualBasic.Vsa.VsaEngine.set_RootMoniker(String value)

at Microsoft.SqlServer.VSAHosting.Runtime.CreateVsaEngine()

at Microsoft.SqlServer.Dts.Pipeline.ScriptRuntime..ctor(String projectName, String moniker, String language, Boolean showErrorUI)

at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.CreateUserComponent()

Error: 0xC0047062 at Data Flow Task, Script Component [53]: System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {A138CF39-2CAE-42C2-ADB3-022658D79F2F} failed with HRESULT: 0x80040154(Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))).

at Microsoft.VisualBasic.Vsa.VsaEngine.CreateEngine()

at Microsoft.VisualBasic.Vsa.VsaEngine.CheckEngine()

at Microsoft.VisualBasic.Vsa.VsaEngine.set_RootMoniker(String value)

at Microsoft.SqlServer.VSAHosting.Runtime.CreateVsaEngine()

at Microsoft.SqlServer.Dts.Pipeline.ScriptRuntime..ctor(String projectName, String moniker, String language, Boolean showErrorUI)

at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.CreateUserComponent()

Error: 0xC004706B at Data Flow Task, DTS.Pipeline: "component "Script Component" (53)" failed validation and returned validation status "VS_ISBROKEN".

Error: 0xC004700C at Data Flow Task, DTS.Pipeline: One or more component failed validation.

Error: 0xC0024107 at Data Flow Task: There were errors during task validation.

SSIS package "src_abs_budg_sales_wc.dtsx" finished: Failure.

The CLSID quoted in the error message is the Visual Studio for Applications runtime, progid "VsaVbRT.8.0," described as "Microsoft Visual Basic Scripting Engine." It looks like the corresponding COM DLL is VsaVb7rt.dll. So it looks like your VSA installation is corrupted or incomplete. Can you try re-registering that DLL using regsvr32.exe?|||

It was my installation that was corrupted, thanks

Script Component can''t find the binary code

Dear all:

I have set the PrecompileScriptIntoBinaryCode property to true,but the Script Component show the message "can't find the binary code" after I finish the script language and save it . What's wrong with it ? I ever tried the same code, and it's OK with no problem. When did the problem happen ?

Please give me a help ....Thanks a lot!

If you are using a x64 Machine then you may face this problem. Under project properties, Debug option, set Run64bitRuntime to false. Now edit your script and save.. Reply if that persists..

Thanks

Subhash Subramanyam

|||And if you're not on 64-bit, make sure you have SP2 installed for SQL Server. (If you just recently applied the Microsoft patches, including the .Net 2.0 security fix, then your scripts will break.)|||

Hi all,

We are running on 32 bit machines with SP2 but still encountered this problem with script components that have been running for months without error. Even if I set almost all code to comment this persists.

This first appeared after the installation of the Microsoft July Security Patches MS07-036 --> MS07-041.

In the end, I was forced to set for these script components precompile to false. Does anyone know if a fix for this problem is planned in a future MS patch?

Kind regards,

|||

Paul,

Take a look through here for a hotfix:

http://support.microsoft.com/kb/931846

|||

Dears,

My problem was solved after installing SQL Server 2005 SP2.

I am in the same situation with Paul . The problem occured since I installed Windows Patches .

Phil, Thank you a lot~~

Script Component can't find the binary code

Dear all:

I have set the PrecompileScriptIntoBinaryCode property to true,but the Script Component show the message "can't find the binary code" after I finish the script language and save it . What's wrong with it ? I ever tried the same code, and it's OK with no problem. When did the problem happen ?

Please give me a help ....Thanks a lot!

If you are using a x64 Machine then you may face this problem. Under project properties, Debug option, set Run64bitRuntime to false. Now edit your script and save.. Reply if that persists..

Thanks

Subhash Subramanyam

|||And if you're not on 64-bit, make sure you have SP2 installed for SQL Server. (If you just recently applied the Microsoft patches, including the .Net 2.0 security fix, then your scripts will break.)|||

Hi all,

We are running on 32 bit machines with SP2 but still encountered this problem with script components that have been running for months without error. Even if I set almost all code to comment this persists.

This first appeared after the installation of the Microsoft July Security Patches MS07-036 --> MS07-041.

In the end, I was forced to set for these script components precompile to false. Does anyone know if a fix for this problem is planned in a future MS patch?

Kind regards,

|||

Paul,

Take a look through here for a hotfix:

http://support.microsoft.com/kb/931846

|||

Dears,

My problem was solved after installing SQL Server 2005 SP2.

I am in the same situation with Paul . The problem occured since I installed Windows Patches .

Phil, Thank you a lot~~