.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Help in error script

Posted By:      Posted Date: October 21, 2010    Points: 0   Category :Sql Server

Hi, Can following error checking script work successfully. I am not sure about this script that it will work effeciently or not.
The pupose of this script to avoid any duplicate values or if any error occur then dont insert any row, should rollback.
Please advise or update this script for fullfill the task.

Begin Tran

insert into p_ben values (12,'H1','HLT','01','C','2011-01-01',134,1,123.85,2)
insert into p_ben values (12,'H1','HLT','01','D','2011-01-01',11,1,45.53,2)
insert into p_ben values (12,'R1','DNT','01','F','2011-01-01',45,1,34.87,2)
insert into p_ben values (12,'R1','DNT','01','S','2011-01-01',56,1,7.81,2)

Errors controlling
if @@error = 0
 commit tran

 print 'Commit is Successfull'
 rollback tran
 print '*** Transaction has been rolled back!'
if @@trancount > 0
 print '*** Error has been occurred'
 rollback tran
 print '*** Transaction has been rolled back!'

Print 'End of script!'

View Complete Post

More Related Resource Links

Incorrect syntax near 'GO' error while running a sql script ?


I am using Visual Studio 2008

I have one Database A

now i want to create Database B just like Database A

I generated a script of Database A

and created fresh Database B

Now, when i try to run the generated script against Database B, i get this error, why ? how to fix it ?

sql error

For your information:

I have checked in my script it is:


and i have also tried to save the sql script in notepad as: ANSI, UTF-8 and UNICODE

and then i copied from txt file to query but still doesn't work and getting the same error

and these are the option that i selected/used while creating my script:


ssrs 2008 R2 - report parameter with no default set throws java script error

We have recently upgraded from SQL Server 2008 to SQL Server 2008 R2....I am experiencing a problem with my report parameters on my SSRS reports. It seems that my report parameters that I do not have a specified 'default' value throws a java script error when I try and run/render the report under R2.  As soon as I put a 'default' value on the report param, everything is fine.  However, that is not the behavior we need for our reports...the user needs to pick their selection. Can anyone shed some light on this, it seems to be an AJAX problem...I need to be able to have report parameters with a list of values, but no 'default' value on the parameter.

SQL Server Powershell script error!

Hi, I get the following error while trying to execute a powershell script. New-Object : Cannot find type [Microsoft.SQlServer.Management.Sdk.Sfc.SqlStoreConnection]: make sure the assembly containing this type is loaded. I'm trying to implement policies across different sql server instances from a primary instance. The script can be found @ http://blogs.msdn.com/sqlpbm/archive/2008/06/14/running-against-sql-server-2005-and-sql-server-2000.aspx Thanks for your help.

Named Pipes provider error - backup script

I have a couple of installs of SQL Server 2005 Express.  One thing it doesn't provide is an agent to schedule jobs so I read where you can use Windows job scheduler to execute a batch job to in turn run a sqlcmd file.  I have that working on one server but on the other server I get the dreaded Name Pipes provider error and it goes on to talk about it may not be setup to allow remote connections.  If I check using Surface Configurator it is set to allow remote connections using both tcpip and named pipes.  To my knowledge all I want it tcpip but I enabled named pipes in an effort to get things working. About the only difference I can see is on the working system the database is a named instance (ie. Servername) versus default instance on the non-working system which shows up as (Servername\SQLEXPRESS).  Hopefully I have my terminology right here. Any tips on how to troubleshoot?  Does it depend on the username I am using?  Domain admin or local server admin or what have you? I should mention I can execute the backup script and it does work.  It is when I run the batch job that it fails. The batch job just says "sqlcmd -i d:\MSSQL_Jobs\backup.sql -o d:\Logs\sqlbackup_output.txt"

Script error in adding users in sharepooint Site

I seem to have a problem when trying to enter new users on a newly built site (SharepointSite). I cannot select the new user option the grant permissions dialog doesn't appear. I'm running MS office 2003 sp3 and ie 7 regards Alan Bateman.

Error in Script component in the Data Flow Task

Hi, I need a small help. This is what i require. I need to generate a auto increment number using script component and assign it to target column. use db1 go create table src (name varchar(10) ) insert into src select 'A' union all select 'B' union all select 'C'   create table trg (id int, name varchar(10) ) while loading the trg table, i need to generate a auto increment number and then load it to target. Finally, my trg table data should look as follows id name 1  A 2  B 3  C This is what i have done inside the package. step1 : declared a global variable "tmp" of int32 step2 : created a connection manager pointing to "db1" database step3 : drag n drop data flow task step : inside the data flow task , i have the following        OLEDB Source  (select name from src)           |        Script Component (i have added a new Output column "v_id" of int datatype in INPUTS AND OUTPUTS page)           |        OLEDB Destination In the Script page in Script component , in ReadWriteVariables | User::tmp, I have chose Visual Basic 2008 and clicked the EDit script and inside the Editor this and inisde the below routine i have added only two

Duplicate column error in script

Hello, I have a new database server and I created a new database and now I'm trying to run a script that's supposed to create all the tables from the previous database server. The script is an accumulation of various changes I have made to the old database since the start of the project in order to implement a variety of features, so it has this pattern: ALTER TABLE X DROP COLUMN Y; GO and later in the file: ALTER TABLE X ADD Y int NOT NULL; GO When I run the script, I get a duplicate column error message for the table and field, although I first dropped the column and then added it again. I suppose I have to do some kind of flash after the drop and before the add, but isn't the GO supposed to do that? If not, how can I flash it in the script? Thanks.  

Insert error description in sysjobhistory from ssis script task

hi. in ssis i have script task that, in some situations, raise error (Dts.TaskResult = ScriptResults.Failure). But in sysjobhistory table there is only shor description what happend (Description: The script returned a failure result.). Is there any way that i can set some system variable to describe what is error so that description ens up in sysjobhistory table? in the end, i want to look in job activity monitor and see that job is "red" and see the description that couses this failure.

Error Trapping in SSIS Script Task

Hi, I am processing a cube partition using an SSIS script task. The script works out the name of the partition which requires processing based on the system date.The problem I have is whenever there is a failure in the processing task the only error I get is that the script task returned a failure result. This is reported by the SQL job that calls the script task and also by SSIS package logging. I am running SQL2005 SP3How can I get my script to return a meningful error? Thanks in advance.

ScriptManager CompositeScript Error: A script reference cannot be included multiple times in composi

I am getting the following error using the CompositeScript feature of the ScriptManager.  I have ScriptManagerProxy in several different usercontrols that use CompositeScript to add whatever JS files they need.  Sometimes there are duplicates which would get removed by the script manager, but that is not happening with the Composite Scripts.  Looking at the stack trace, it calls RemoveDuplicates but for some reason it doesn't do so.  Is this a bug?  Is there a workaround or a hotfix? Thanks! A script reference cannot be included multiple times in composite script references. Stack Trace: [InvalidOperationException: A script reference cannot be included multiple times in composite script references.]   System.Web.UI.ScriptManager.RemoveDuplicates(List`1 scripts) +698   System.Web.UI.ScriptManager.RegisterScripts() +328   System.Web.UI.ScriptManager.OnPagePreRenderComplete(Object sender, EventArgs e) +113   System.Web.UI.Page.OnPreRenderComplete(EventArgs e) +8695102   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1029

SQL Server 2008 Script Componant Error - [SSIS.Pipeline] Error: component "Script Comp Name" (48) fa

Hi All,   I am facing one strange issue in SSIS 2008. I have developed one SSIS package which is importing excel data into SQL Server 2008. This Package contains some Scirpt componants. This package is working fine on Windows XP machine but when I am trying to run on Windows 2003 server it gives me error "[SSIS.Pipeline] Error: component "SCR RDSTableRelation" (48) failed the post-execute phase and returned error code 0x80004002". Surprising thing is that if on windows server 2003server  if I drag a new script componat and paste the previous script code itself then it works fine. Even if I copy-paste the existing script componant and give source-destination connectino to this new script componant then also it works.

stop running this script error in htmleditor

Hello, I am using AjaxToolkit 3.5 for HTMLEditor contorl. In one of the form i have pasted around 50 pages of word document. While i tried to save the input to the database, i get javascript popup error message saying "Stop running the script". Any help would be appreciated.  

Error when running an SQL script to restore a database on SQL Server 2008 R2 Express

Hi, At work, I use SQL Server 2008 Express running on Windows XP Professional Service Pack 3. At home, I also use SQL Server 2008 Express running on Windows XP Professional Service Pack 3. Whenever I do work on the database at work, I usually restore the database at home (or vice versa) I have been using the following SQL scripts to back up the database and to restore the same database (at work or at home). BackupRealEstate.sql USE Master BACKUP DATABASE [RealEstate] TO DISK = N'F:\My Documents\My Database\RealEstate.bak' WITH NOFORMAT, INIT, NAME = N'RealEstate-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10 GO RestoreRealEstate.sql USE Master RESTORE DATABASE [RealEstate] FROM DISK = N'F:\My Documents\My Database\RealEstate.bak' WITH  FILE = 1, NOUNLOAD, REPLACE, STATS = 10 GO Everything worked fine until I replaced my 8yo home computer with a newer and faster one. My new home computer is running Windows 7 Home Premium and I use the latest SQL Server 2008 R2 Express. When I tried to run the above restore SQL script, I got the following error message: Msg 3101, Level 16, State 1, Line 2 Exclusive access could not be obtained because the database is in use. Msg 3013, Level 16, State 1, Line 2 RESTORE DATABASE is terminating abnormally. There was no other application/process using this database. Can someone please help me? Regards,

Script error when opening document menu

Hello,   Two of our MOSS users found strange problem when they tried to open or edit document in document library. When they try to open document menu, IE gives error:   Internet Explorer Script Error Line: 578 Char: 1 Error: Object expected Code: 0 URL:  http://<servername>/<sitecollection>/<site>/<documentlibrary>/AllItems.aspx   Do you want to continue running scripts on this page? Yes / No   Can anyone help me what to do? Users cannot do anything with documents now.   Best Regards Toni

Error in MDX script

Dear All, I am facing a problem in the following MDX script.   ----------------------------------------------- with member  [measures].[invcnt] as count(  (  filter( [Inventory Region Map].[Location Map].[LocationID]* ([Time].[Trade YWD].currentmember)*([Inventory Region Map].[Inventory Business Map].[CountryID].&[AE])*([Product].[Brand].[BrandID].&[BOSSINI])*([InHouse Sale].&[Standard]),  [Measures].[InventoryQtyCB]>=1 or [Measures].[ItemSalesQty]>=1 )   )  )   SELECT NON EMPTY {[measures].[invcnt]} ON COLUMNS,    NON EMPTY { ([Time].[Trade YWD].[Week].ALLMEMBERS * [Product].[Option].[OptionID].ALLMEMBERS ) }     DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM     ( SELECT ( [Time].[Trade YWD].[Trade YWD].[2010].[2010W25] : [Time].[Trade YWD].[Trade YWD].[2010].[2010W26] )     ON COLUMNS FROM ( SELECT ( { [InHouse Sale].&[Standard] } ) ON COLUMNS FROM     ( SELECT ( { [Product].[Season Classification].[BrandID].&[BOSSINI].&[CUR BOSSINI].&[62010 BOSSINI], [Product].[Season Classification].[BrandID].&[BOSSINI].&[PRI BOSSINI].&[42009 BOSSINI] } ) ON COLUMNS FROM     ( SELECT ( { [Product].[All Levels].[BrandID].&[BOSSINI].&[1 BOSSINI].&[00 BOSSINI 1].&[SICXX BOSSINI 1

script task error

Hi EVERYbody,   i am trying to write C# code in this task but idont know how to write this is there any alternate is there instead of Writing C# code.   I heard C# code instead of we will write sql statement can any body give some examples or exsizes on this i need write some code on script task plz help me.   Thankssubu

IE script error (object expected) on treeview

Hi,Just starting out with the CSS adapters and have implemented a treeview. Works fine in Firefox butIE shows a script error (bottom left) when moving over the tree view. It still goes to the page but there is obviously an issuePage code is in a master page below is the source view in IE<script type="text/javascript">//<![CDATA[var theForm = document.forms['aspnetForm'];if (!theForm) {    theForm = document.aspnetForm;}function __doPostBack(eventTarget, eventArgument) {    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {        theForm.__EVENTTARGET.value = eventTarget;        theForm.__EVENTARGUMENT.value = eventArgument;        theForm.submit();    }}//]]></script><script src="/countrystovesdirect/WebResource.axd?d=KFBAefcFIGtf1hLcg-tm2g2&amp;t=634172878000000000" type="text/javascript"></script><script src="/countrystovesdirect/WebResource.axd?d=S53dmqAagvRk26h8P3H5I9pat_c17l9dW6l04Xdzs9Ai0yVsPFqiIf_M-ylpvzDHp0GeDDnhMnCondcznfbzzw2&amp;t=634201551800000000" type="text/javascript"></script><script src="/countrystovesdirect/WebResource.axd?d=S53dmqAagvRk26h8P3H5I9pat_c17l9dW6l04Xdzs9ACFhsw16G3-NkgCeZFVUFx6W
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend