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
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to execute sql script from asp.net, need help

How to execute sql script from asp.net, need help

Scheduled Pinned Locked Moved ASP.NET
databasecsharpasp-nettoolshelp
9 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.
  • D Offline
    D Offline
    dream_liner_7e7
    wrote on last edited by
    #1

    I have a database script which include my custom tables and asp.net roles and membership structure also and i have to execute it from asp.net, i tried but getting errors, all i did through stream read i saved the whole script in string s and then through executenonquery i m trying to run it but getting page full of errors System.Data.SqlClient.SqlException: The variable name '@RoleName' has already been declared. Variable names must be unique within a query batch or stored procedure. The variable name '@RoleMemberName' has already been declared. Variable names must be unique within a query batch or stored procedure. Plz help Thanks in advance.

    K A 2 Replies Last reply
    0
    • D dream_liner_7e7

      I have a database script which include my custom tables and asp.net roles and membership structure also and i have to execute it from asp.net, i tried but getting errors, all i did through stream read i saved the whole script in string s and then through executenonquery i m trying to run it but getting page full of errors System.Data.SqlClient.SqlException: The variable name '@RoleName' has already been declared. Variable names must be unique within a query batch or stored procedure. The variable name '@RoleMemberName' has already been declared. Variable names must be unique within a query batch or stored procedure. Plz help Thanks in advance.

      K Offline
      K Offline
      Kannan Ar
      wrote on last edited by
      #2

      The error message is self-explanatory. SQL variable names are declared multiple times.

      1 Reply Last reply
      0
      • D dream_liner_7e7

        I have a database script which include my custom tables and asp.net roles and membership structure also and i have to execute it from asp.net, i tried but getting errors, all i did through stream read i saved the whole script in string s and then through executenonquery i m trying to run it but getting page full of errors System.Data.SqlClient.SqlException: The variable name '@RoleName' has already been declared. Variable names must be unique within a query batch or stored procedure. The variable name '@RoleMemberName' has already been declared. Variable names must be unique within a query batch or stored procedure. Plz help Thanks in advance.

        A Offline
        A Offline
        Ashfield
        wrote on last edited by
        #3

        As the error says, the @RoleMemberName' has been declared more than once. You may well end up with other errors as (for example) you cannot reference a function within your code until the function has been created. The best bet is to put your sql into query analyser, run it, fix the problems (repeat until clean) and then use that script from your application.

        Bob Ashfield Consultants Ltd

        D 1 Reply Last reply
        0
        • A Ashfield

          As the error says, the @RoleMemberName' has been declared more than once. You may well end up with other errors as (for example) you cannot reference a function within your code until the function has been created. The best bet is to put your sql into query analyser, run it, fix the problems (repeat until clean) and then use that script from your application.

          Bob Ashfield Consultants Ltd

          D Offline
          D Offline
          dream_liner_7e7
          wrote on last edited by
          #4

          but i am trying to execute the script in newly created database, i think the problem is in reading the script into string var, normally the same script is working fi9 in sql server. Any idea how should i read the script in asp.net? Thanks in Advance.

          A 1 Reply Last reply
          0
          • D dream_liner_7e7

            but i am trying to execute the script in newly created database, i think the problem is in reading the script into string var, normally the same script is working fi9 in sql server. Any idea how should i read the script in asp.net? Thanks in Advance.

            A Offline
            A Offline
            Ashfield
            wrote on last edited by
            #5

            It is nothing to do with taht, I bet if you take the string you are trying to run, paste it into a query analyser window in a new database and run it you will get exactly the same error. This error is caused by not havng a GO statment between each part, therefore your variable is declared twice. I wouldn't be suprised if other errors crop up when you have fixed this one, for example expect to see errors like 'Create xxx must be the first statemnt in th batch'

            dream_liner_7e7 wrote:

            Any idea how should i read the script in asp.net?

            What ou are doing will be OK, asp.net is not teh problem, its your sql!

            Bob Ashfield Consultants Ltd

            D 2 Replies Last reply
            0
            • A Ashfield

              It is nothing to do with taht, I bet if you take the string you are trying to run, paste it into a query analyser window in a new database and run it you will get exactly the same error. This error is caused by not havng a GO statment between each part, therefore your variable is declared twice. I wouldn't be suprised if other errors crop up when you have fixed this one, for example expect to see errors like 'Create xxx must be the first statemnt in th batch'

              dream_liner_7e7 wrote:

              Any idea how should i read the script in asp.net?

              What ou are doing will be OK, asp.net is not teh problem, its your sql!

              Bob Ashfield Consultants Ltd

              D Offline
              D Offline
              dream_liner_7e7
              wrote on last edited by
              #6

              U are very right, when reading the script in asp.net i m not including the go statement because even including the environment.newline it is only giving the single space and when go statement and other statement come in same line sql through error. Thanks alot u r the best.

              1 Reply Last reply
              0
              • A Ashfield

                It is nothing to do with taht, I bet if you take the string you are trying to run, paste it into a query analyser window in a new database and run it you will get exactly the same error. This error is caused by not havng a GO statment between each part, therefore your variable is declared twice. I wouldn't be suprised if other errors crop up when you have fixed this one, for example expect to see errors like 'Create xxx must be the first statemnt in th batch'

                dream_liner_7e7 wrote:

                Any idea how should i read the script in asp.net?

                What ou are doing will be OK, asp.net is not teh problem, its your sql!

                Bob Ashfield Consultants Ltd

                D Offline
                D Offline
                dream_liner_7e7
                wrote on last edited by
                #7

                Plz tell me how should i read the sql script in asp.net so i dont get go or same variable error and this sql script also include aspnetDB. Thanks in advance.

                A 1 Reply Last reply
                0
                • D dream_liner_7e7

                  Plz tell me how should i read the sql script in asp.net so i dont get go or same variable error and this sql script also include aspnetDB. Thanks in advance.

                  A Offline
                  A Offline
                  Ashfield
                  wrote on last edited by
                  #8

                  I have already told you how to fix the problem, the error is caused by not havng a GO statment between each part.

                  dream_liner_7e7 wrote:

                  how should i read the sql script

                  Wthout knowing what the script consists of how do you expect me to do ths? If it is a single script then you cannot put the go statements in as you do not know where to put them, so you need to do it at the point of concatenating the scripts together.

                  dream_liner_7e7 wrote:

                  and this sql script also include aspnetD

                  Don't understand ths bit at all. I'm afraid you are now on your own - you know the problem, so find a solution.

                  Bob Ashfield Consultants Ltd

                  D 1 Reply Last reply
                  0
                  • A Ashfield

                    I have already told you how to fix the problem, the error is caused by not havng a GO statment between each part.

                    dream_liner_7e7 wrote:

                    how should i read the sql script

                    Wthout knowing what the script consists of how do you expect me to do ths? If it is a single script then you cannot put the go statements in as you do not know where to put them, so you need to do it at the point of concatenating the scripts together.

                    dream_liner_7e7 wrote:

                    and this sql script also include aspnetD

                    Don't understand ths bit at all. I'm afraid you are now on your own - you know the problem, so find a solution.

                    Bob Ashfield Consultants Ltd

                    D Offline
                    D Offline
                    dream_liner_7e7
                    wrote on last edited by
                    #9

                    Thanks a lot Sir. U r the best.

                    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