script to create table + schema + stored procedure+ ....

  • Hello,

    I am writing a script which must be able to create a database, add tables to that database, add stored procedures.

    you can find the script attached

    But The first time I run this script it gives me these errors.

    Msg 2760, Level 16, State 1, Line 6

    The specified schema name "nagios" either does not exist or you do not have permission to use it.

    Msg 2760, Level 16, State 1, Procedure fix, Line 5

    The specified schema name "nagios" either does not exist or you do not have permission to use it.

    Msg 2760, Level 16, State 1, Procedure SHOW_NONCRITICAL_FAILED_JOBS, Line 11

    The specified schema name "nagios" either does not exist or you do not have permission to use it.

    Msg 2760, Level 16, State 1, Procedure SHOW_CRITICAL_FAILED_JOBS, Line 11

    The specified schema name "nagios" either does not exist or you do not have permission to use it.

    Msg 2760, Level 16, State 1, Procedure NAGIOSINPUT, Line 6

    The specified schema name "nagios" either does not exist or you do not have permission to use it.

    Msg 2760, Level 16, State 1, Procedure CHECK_DATABASE_EXISTS, Line 14

    The specified schema name "nagios" either does not exist or you do not have permission to use it.

    Msg 2760, Level 16, State 1, Line 3

    The specified schema name "nagios" either does not exist or you do not have permission to use it.

    Msg 2760, Level 16, State 1, Procedure show_login_errors, Line 15

    The specified schema name "nagios" either does not exist or you do not have permission to use it.

    Msg 2760, Level 16, State 1, Procedure CHECK_DATA_SIZE, Line 64

    The specified schema name "nagios" either does not exist or you do not have permission to use it.

    Msg 2760, Level 16, State 1, Procedure CHECK_FAILED_LOGINS, Line 48

    The specified schema name "nagios" either does not exist or you do not have permission to use it.

    Msg 2760, Level 16, State 1, Procedure CHECK_NONCRITICAL_FAILED_JOBS, Line 33

    The specified schema name "nagios" either does not exist or you do not have permission to use it.

    Msg 2760, Level 16, State 1, Procedure CHECK_CRITICAL_FAILED_JOBS, Line 57

    The specified schema name "nagios" either does not exist or you do not have permission to use it.

    Msg 2760, Level 16, State 1, Procedure CHECK_LAST_BACKUP, Line 47

    The specified schema name "nagios" either does not exist or you do not have permission to use it.

    Msg 2760, Level 16, State 1, Procedure CHECK_DATABASE_STATUS, Line 53

    The specified schema name "nagios" either does not exist or you do not have permission to use it.

    Msg 2760, Level 16, State 1, Procedure CHECK_WEAK_PASSWORDS, Line 102

    The specified schema name "nagios" either does not exist or you do not have permission to use it.

    Msg 2760, Level 16, State 1, Procedure CHECK_USER, Line 3

    The specified schema name "nagios" either does not exist or you do not have permission to use it.

    Msg 2760, Level 16, State 1, Procedure CHECK_UPTIME, Line 29

    The specified schema name "nagios" either does not exist or you do not have permission to use it.

    Msg 2760, Level 16, State 1, Procedure CHECK_LOG_SIZE, Line 51

    The specified schema name "nagios" either does not exist or you do not have permission to use it.

    Msg 2760, Level 16, State 1, Procedure CHECK_DATABASE_STATUS2, Line 54

    The specified schema name "nagios" either does not exist or you do not have permission to use it.

    Msg 2760, Level 16, State 1, Procedure CHECK_CONNECTIONS, Line 39

    The specified schema name "nagios" either does not exist or you do not have permission to use it.

    Msg 3902, Level 16, State 1, Line 51

    The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.

    when I run the script for the second time. No problemo.

    I believe

    The first run it creates the db and the schema etc. But it is not yet recognised by the end part of the script.(the part of adding tables, stored procedures etc. etc to that db)

    How can I fix this so I only have to run this one time?

    Thanks.

  • Looks like the first time you run the SQL, the database context is unknown but the second time, the context is the user database.

    Move the "Use [nagios]" statement before you create the users/schema.

    SQL = Scarcely Qualifies as a Language

  • Carl Federl (5/20/2008)


    Looks like the first time you run the SQL, the database context is unknown but the second time, the context is the user database.

    Move the "Use [nagios]" statement before you create the users/schema.

    ==> this puts all the stored procedures and tables in the master database. and doesn't create the nagios db.

  • Hi Steve,

    Put the use database statement mentioned above directly after the create database. This will ensure any statements after the use database statement will be aimed at the correct database.

    Matt.

  • thanks.

    I fixed it thanks to you guys

  • Nice to hear!

    Thanks,

    Matt.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply