Welcome to Sign in | Help
in Search

Backup procedure Msg 170 Incorrect syntax near

Last post 10-23-2006, 3:30 PM by xmldeveloper. 13 replies.
Sort Posts: Previous Next
  •  10-19-2006, 10:29 AM 423

    Backup procedure Msg 170 Incorrect syntax near

    Sunt destul de nou in treburile astea legate de sql. Lucrez la intretinerea unei aplicatii care foloseste SQL Server Express edition.

    Am incercat sa gasesc o strategie de backup automata, si am gasit un exemplu pe net http://www.sqldbatips.com/showarticle.asp?ID=27 despre un stored procedure care poate sa faca treaba asta. Cand incerc sa rulez codul imi da 2 tipuri de erori:

    Msg 170, Level 15, State 1, Procedure expressmaint, Line 404

    Line 404: Incorrect syntax near 'CATCH'.

    Msg 156, Level 15, State 1, Procedure expressmaint, Line 428

    Incorrect syntax near the keyword 'END'.

    legate de cele doua tipuri de structuri. Sincer nu stiu care poate sa fie problema am vazut cateva raspunsuri pe ici pe colo dar care nu m-au lamurit.

    Daca ma poate ajuta cineva cu rezolvarea acestei probleme, sau daca se stie despre vreo alta metoda de backup automata.

    Mersi

  •  10-19-2006, 10:43 AM 426 in reply to 423

    Re: Backup procedure Msg 170 Incorrect syntax near

    Ce cod rulati exact?

    Mie imi merge crearea procedurii stocate expressmaint.

     


    Cristian Andrei Lefter, SQL Server MVP
    MCT, MCSA, MCDBA, MCAD, MCSD .NET,
    MCTS, MCITP - Database Administrator SQL Server 2005
    http://sqlserver.ro
  •  10-19-2006, 10:56 AM 430 in reply to 426

    Re: Backup procedure Msg 170 Incorrect syntax near

    AM instalat si sqlcmd si am efectua exact pasii de acolo. Am rulat exact codul care era acolo, dupa ce am creat fisierul c:\expressmaint.sql

    am folosit sqlcmd comanda

    sqlcmd -S SERVICE -i c:\expressmaint.sql

    Poate sa fie vreo problema legata de faptul ca Sql Server 2005 ii doar editia express.

    Imi cer scuze daca nu am fost suficient de explicit
  •  10-19-2006, 11:04 AM 435 in reply to 430

    Re: Backup procedure Msg 170 Incorrect syntax near

    1. SQL Express e instalat ca instanta default?
    2. Va merge sqlcmd -S SERVICE?
    3. Ati download-at codul de aici: http://www.sqldbatips.com/samples/code/9/expressmaint.zip (arhiva are un fisier txt). ?

    Poate sa fie vreo problema legata de faptul ca Sql Server 2005 ii doar editia express.

    Din contra, scriptul este facut pentru editia express!

     

     


    Cristian Andrei Lefter, SQL Server MVP
    MCT, MCSA, MCDBA, MCAD, MCSD .NET,
    MCTS, MCITP - Database Administrator SQL Server 2005
    http://sqlserver.ro
  •  10-19-2006, 12:23 PM 438 in reply to 435

    Re: Backup procedure Msg 170 Incorrect syntax near

    Nu stiu exact daca e instanta default. Dar comanda specificata da merge si executa conexiunea la server.

    De copiat am copiat din fisierul lor si l-am salvat cu extensia sql.

    Insa am remarcat ca in query editor si alte coduri imi dau erori asemanatoare!

     

  •  10-19-2006, 2:42 PM 446 in reply to 438

    Re: Backup procedure Msg 170 Incorrect syntax near

    Nu va pot da un raspuns complet decat pe un caz concret.

    Va sfatuiesc sa descarcati SQL Server Management Studio Express, un utilitar free de management de la adresa http://msdn.microsoft.com/vstudio/express/sql/download/ (sau direct http://go.microsoft.com/fwlink/?LinkId=65110).

    Rulati pe urma scriptul din SQL Server Management Studio Express si vedeti unde apare problema mai exact.


    Cristian Andrei Lefter, SQL Server MVP
    MCT, MCSA, MCDBA, MCAD, MCSD .NET,
    MCTS, MCITP - Database Administrator SQL Server 2005
    http://sqlserver.ro
  •  10-23-2006, 10:01 AM 471 in reply to 446

    Re: Backup procedure Msg 170 Incorrect syntax near

    Eroarea apare in la structurile de try and catch in contextul executiei unei comenzi. Exemplific cu o astfel de comanda si locul unde este reportata o eraoare:

    IF UPPER(@optype) = 'DB'

    BEGIN

    UPPER(@optype) = 'DB'

    BEGIN

    BEGIN

     

    SET @execmd = N'BACKUP DATABASE [' + @database + '] TO DISK = ''' + @backupfilename + '''' +

    SET @execmd = N'BACKUP DATABASE [' + @database + '] TO DISK = ''' + @backupfilename + '''' +

    CASE WHEN @backupwith IS NULL THEN '' ELSE (' WITH ' + @backupwith) END

    CASE WHEN @backupwith IS NULL THEN '' ELSE (' WITH ' + @backupwith) END

     

    BEGIN TRY -- Incorrect syntax near 'TRY'

     

    EXEC(@execmd)

    BEGIN TRY -- Incorrect syntax near 'TRY'

     

    EXEC(@execmd)

    EXEC(@execmd)

     

    END TRY -- Incorrect syntax near 'T

    BEGIN CATCH -- backup failure

    END TRY -- Incorrect syntax near 'T

    BEGIN CATCH -- backup failure

    BEGIN CATCH -- backup failure

    SELECT @err = @@ERROR,@ret = @err

    SELECT @errormsg = 'Full backup of database ' + @database + ' failed with error : ' + CAST(@err as varchar(10))

    SELECT @err = @@ERROR,@ret = @err

    SELECT @errormsg = 'Full backup of database ' + @database + ' failed with error : ' + CAST(@err as varchar(10))

    SELECT @errormsg = 'Full backup of database ' + @database + ' failed with error : ' + CAST(@err as varchar(10))

    SET @output = SPACE(4) + '*** ' + @errormsg + ' ***'

    IF @debug = 1 PRINT @output

    IF @report = 1

    BEGIN

    SET @output = SPACE(4) + '*** ' + @errormsg + ' ***'

    IF @debug = 1 PRINT @output

    IF @report = 1

    BEGIN

    IF @debug = 1 PRINT @output

    IF @report = 1

    BEGIN

    IF @report = 1

    BEGIN

    BEGIN

    EXEC sp_OAMethod @file,'WriteLine',NULL,@output

    SET @output = SPACE(4) + 'Refer to SQL Error Log and NT Event Log for further details'

    EXEC sp_OAMethod @file,'WriteLine',NULL,@output

    EXEC sp_OAMethod @file,'WriteLine',NULL,''

    END

    EXEC sp_OAMethod @file,'WriteLine',NULL,@output

    SET @output = SPACE(4) + 'Refer to SQL Error Log and NT Event Log for further details'

    EXEC sp_OAMethod @file,'WriteLine',NULL,@output

    EXEC sp_OAMethod @file,'WriteLine',NULL,''

    END

    SET @output = SPACE(4) + 'Refer to SQL Error Log and NT Event Log for further details'

    EXEC sp_OAMethod @file,'WriteLine',NULL,@output

    EXEC sp_OAMethod @file,'WriteLine',NULL,''

    END

    EXEC sp_OAMethod @file,'WriteLine',NULL,@output

    EXEC sp_OAMethod @file,'WriteLine',NULL,''

    END

    EXEC sp_OAMethod @file,'WriteLine',NULL,''

    END

    END

    CLOSE dcur

    DEALLOCATE dcur

    GOTO CLEANUP

     

    END CATCH --Incorrect syntax near 'CATCH'

    CLOSE dcur

    DEALLOCATE dcur

    GOTO CLEANUP

     

    END CATCH --Incorrect syntax near 'CATCH'

    DEALLOCATE dcur

    GOTO CLEANUP

     

    END CATCH --Incorrect syntax near 'CATCH'

    GOTO CLEANUP

     

    END CATCH --Incorrect syntax near 'CATCH'

    END CATCH --Incorrect syntax near 'CATCH'
  •  10-23-2006, 10:38 AM 472 in reply to 471

    Re: Backup procedure Msg 170 Incorrect syntax near

    Rulati urmatorul cod si redati rezultatul: EXEC dbo.sp_dbcmptlevel @dbname=N'master';

     


    Cristian Andrei Lefter, SQL Server MVP
    MCT, MCSA, MCDBA, MCAD, MCSD .NET,
    MCTS, MCITP - Database Administrator SQL Server 2005
    http://sqlserver.ro
  •  10-23-2006, 10:53 AM 473 in reply to 472

    Re: Backup procedure Msg 170 Incorrect syntax near

    Rezultatul la comanda rulata este :

    The current compatibility level is 80.

  •  10-23-2006, 12:08 PM 474 in reply to 473

    Re: Backup procedure Msg 170 Incorrect syntax near

    Asta e problema Smile

    Rulati in modul de compatibilitate cu SQL Server 2000 (8.0). Puteti rezolva problema ruland:

    EXEC sp_dbcmptlevel N'master', 90;
    GO


    Cristian Andrei Lefter, SQL Server MVP
    MCT, MCSA, MCDBA, MCAD, MCSD .NET,
    MCTS, MCITP - Database Administrator SQL Server 2005
    http://sqlserver.ro
  •  10-23-2006, 1:38 PM 475 in reply to 474

    Re: Backup procedure Msg 170 Incorrect syntax near

    Probabil asta era problema insa si ruland codul de mai sus imi eroare:

    Msg 15417, Level 16, State 1, Procedure sp_dbcmptlevel, Line 82

    Cannot change the compatibility level of the 'master' database.

  •  10-23-2006, 2:20 PM 476 in reply to 475

    Re: Backup procedure Msg 170 Incorrect syntax near

    Pentru a putea schimba nivelul de compatibilitate este necesar sa nu existe utilizatori conectati la baza de date.

    Din ce am inteles eu aveti totusi SQL Server 2005. In mod normal ar trebui ca baza de date master sa fie in modul de compatibilitate 90. Ce afiseaza SELECT @@VERSION ?


    Cristian Andrei Lefter, SQL Server MVP
    MCT, MCSA, MCDBA, MCAD, MCSD .NET,
    MCTS, MCITP - Database Administrator SQL Server 2005
    http://sqlserver.ro
  •  10-23-2006, 2:45 PM 477 in reply to 476

    Re: Backup procedure Msg 170 Incorrect syntax near

    Cand am rulatcodul mi-am dat seama ce prost is.

    Aveam instalat si sql 2000 si de fapt ma conectam la serverul de 2000 de aceea nu aveam posibilitatea sa modific nivelul de compatibilitate la 90. Citisem si eu pe net si am vazut ca normal trebuia sa fie implicit nivel 90.

    Imi cer scuze ca te-am batut la cap atata. Is la inceput si nu prea le am asa de bine.Big Smile

    Oricum toata stima pentru ajutorul tau. Si sper ca o sa ma mai ajuti daca e cazul!Big Smile

  •  10-23-2006, 3:30 PM 478 in reply to 477

    Re: Backup procedure Msg 170 Incorrect syntax near

    Deci banuiala mea era corecta Smile

    De asta v-am rugat sa rulati SELECT @@VERSION !

    Nu va faceti griji, se poate intampla oricui.


    Cristian Andrei Lefter, SQL Server MVP
    MCT, MCSA, MCDBA, MCAD, MCSD .NET,
    MCTS, MCITP - Database Administrator SQL Server 2005
    http://sqlserver.ro
View as RSS news feed in XML
Powered by Community Server (Commercial Edition), by Telligent Systems