How to execute sql script from asp.net, need help
-
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.
-
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.
-
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.
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
-
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
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.
-
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.
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
-
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
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.
-
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
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.
-
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.
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
-
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
Thanks a lot Sir. U r the best.