Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Creating multiple sql stored procedures from vb .net

Creating multiple sql stored procedures from vb .net

Scheduled Pinned Locked Moved Database
databasehelpcsharpsharepointquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    iramirezp
    wrote on last edited by
    #1

    Hi everyone, I'm creating a database installer where I have some code to create database, tables, stored procedures, etc. I don't have problems when creating the database, tables and inserting required data. My problem is when my code gets to the stored procedures section. Here is what I do: I have different text files (database.txt, tables.txt, insertdata.txt, storeprocedures.txt) where my sql syntax is located. I execute every process/text file using the following: ExecuteSql("master", GetSql("database.txt")) ' Creating 1 database. ExecuteSql("mynewdatabase", GetSql("tables.txt")) ' Creating 15 tables. ExecuteSql("mynewdatabase", GetSql("insertdata.txt")) ' Inserting data to many tables. ExecuteSql("mynewdatabase", GetSql("storeprocedures.txt")) ' Creating 6 stored procedures. Here is part of the error: In exception handler: Incorrect syntax near the keyword 'PROCEDURE'. "This is the second stored procedure because the variables I get below belong to the second one" Must declare the scalar variable "@intVariable1". Must declare the scalar variable "@intVariable1". Must declare the scalar variable "@intVariable1". Must declare the scalar variable "@intVariable1". When trying to create 6 or even 2 stored procedures using the same file ‘storeprocedures.txt' is not possible. If I leave just 1 it works but I really want to keep them together. Creating 15 tables using the same file 'tables.txt' works, inserting data in different tables using the same file 'insertdata.txt' works. This is the general syntax I use: Create Procedure sp_stored1 @intVariablex int As Begin Code End Create Procedure sp_stored2 intVariabley int As Begin Code End .......... .......... .......... Is is possible to create more than 1 stored procedure the way I'm trying to? Do I need to end every stored procedure with specific sql syntax, other than the 'end'? I appreciate your response!!! Thanks, Israel

    N R 2 Replies Last reply
    0
    • I iramirezp

      Hi everyone, I'm creating a database installer where I have some code to create database, tables, stored procedures, etc. I don't have problems when creating the database, tables and inserting required data. My problem is when my code gets to the stored procedures section. Here is what I do: I have different text files (database.txt, tables.txt, insertdata.txt, storeprocedures.txt) where my sql syntax is located. I execute every process/text file using the following: ExecuteSql("master", GetSql("database.txt")) ' Creating 1 database. ExecuteSql("mynewdatabase", GetSql("tables.txt")) ' Creating 15 tables. ExecuteSql("mynewdatabase", GetSql("insertdata.txt")) ' Inserting data to many tables. ExecuteSql("mynewdatabase", GetSql("storeprocedures.txt")) ' Creating 6 stored procedures. Here is part of the error: In exception handler: Incorrect syntax near the keyword 'PROCEDURE'. "This is the second stored procedure because the variables I get below belong to the second one" Must declare the scalar variable "@intVariable1". Must declare the scalar variable "@intVariable1". Must declare the scalar variable "@intVariable1". Must declare the scalar variable "@intVariable1". When trying to create 6 or even 2 stored procedures using the same file ‘storeprocedures.txt' is not possible. If I leave just 1 it works but I really want to keep them together. Creating 15 tables using the same file 'tables.txt' works, inserting data in different tables using the same file 'insertdata.txt' works. This is the general syntax I use: Create Procedure sp_stored1 @intVariablex int As Begin Code End Create Procedure sp_stored2 intVariabley int As Begin Code End .......... .......... .......... Is is possible to create more than 1 stored procedure the way I'm trying to? Do I need to end every stored procedure with specific sql syntax, other than the 'end'? I appreciate your response!!! Thanks, Israel

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      Try placing GO between each store proc creation script to separate each batch


      I know the language. I've read a book. - _Madmatt

      I 1 Reply Last reply
      0
      • N Not Active

        Try placing GO between each store proc creation script to separate each batch


        I know the language. I've read a book. - _Madmatt

        I Offline
        I Offline
        iramirezp
        wrote on last edited by
        #3

        Thanks Mark but I have tried that and only works when using the sql editor. I actually had to remove the GO from my other text files (database.txt, tables.txt) in order to work. Thanks, Israel

        1 Reply Last reply
        0
        • I iramirezp

          Hi everyone, I'm creating a database installer where I have some code to create database, tables, stored procedures, etc. I don't have problems when creating the database, tables and inserting required data. My problem is when my code gets to the stored procedures section. Here is what I do: I have different text files (database.txt, tables.txt, insertdata.txt, storeprocedures.txt) where my sql syntax is located. I execute every process/text file using the following: ExecuteSql("master", GetSql("database.txt")) ' Creating 1 database. ExecuteSql("mynewdatabase", GetSql("tables.txt")) ' Creating 15 tables. ExecuteSql("mynewdatabase", GetSql("insertdata.txt")) ' Inserting data to many tables. ExecuteSql("mynewdatabase", GetSql("storeprocedures.txt")) ' Creating 6 stored procedures. Here is part of the error: In exception handler: Incorrect syntax near the keyword 'PROCEDURE'. "This is the second stored procedure because the variables I get below belong to the second one" Must declare the scalar variable "@intVariable1". Must declare the scalar variable "@intVariable1". Must declare the scalar variable "@intVariable1". Must declare the scalar variable "@intVariable1". When trying to create 6 or even 2 stored procedures using the same file ‘storeprocedures.txt' is not possible. If I leave just 1 it works but I really want to keep them together. Creating 15 tables using the same file 'tables.txt' works, inserting data in different tables using the same file 'insertdata.txt' works. This is the general syntax I use: Create Procedure sp_stored1 @intVariablex int As Begin Code End Create Procedure sp_stored2 intVariabley int As Begin Code End .......... .......... .......... Is is possible to create more than 1 stored procedure the way I'm trying to? Do I need to end every stored procedure with specific sql syntax, other than the 'end'? I appreciate your response!!! Thanks, Israel

          R Offline
          R Offline
          RCoate
          wrote on last edited by
          #4

          iramirezp wrote:

          Create Procedure sp_stored1 @intVariablex int

          iramirezp wrote:

          Create Procedure sp_stored2 intVariabley int

          Not sure if this is just a typo, but you seem to be missing a @ in the second Sproc

          I 1 Reply Last reply
          0
          • R RCoate

            iramirezp wrote:

            Create Procedure sp_stored1 @intVariablex int

            iramirezp wrote:

            Create Procedure sp_stored2 intVariabley int

            Not sure if this is just a typo, but you seem to be missing a @ in the second Sproc

            I Offline
            I Offline
            iramirezp
            wrote on last edited by
            #5

            It was a typo in the example I put just to have an idea how I have the stored procedures lines.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups