By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,476 Members | 889 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,476 IT Pros & Developers. It's quick & easy.

update database through SQL script

P: n/a
I am doing customization for Microsoft Pos. I am working on
installation package now. I added some new tables and stored
procuedures and generated SQL Script for that. During the installation
process, after user entered the server name and database name, how to
open the script file (*.sql) and run that to update database? So they
don't have to open Query Analizer to run it. The idea is to get
everything done during the installation process. Anyone got an idea?

Thanks in advance.

Leanne

Nov 9 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Leanne,

You can run every script using the SQLCommand.executenonquery, therefore as
well Create and Alter statements.

http://msdn2.microsoft.com/en-us/lib...enonquery.aspx

I hope this helps,

Cor
"Leanne" <le******@connectretail.com.auschreef in bericht
news:11**********************@f16g2000cwb.googlegr oups.com...
>I am doing customization for Microsoft Pos. I am working on
installation package now. I added some new tables and stored
procuedures and generated SQL Script for that. During the installation
process, after user entered the server name and database name, how to
open the script file (*.sql) and run that to update database? So they
don't have to open Query Analizer to run it. The idea is to get
everything done during the installation process. Anyone got an idea?

Thanks in advance.

Leanne

Nov 9 '06 #2

P: n/a
Cor,
Thank you for your reply. My problem is, the generated SQL script
contains a lot " if exist...then drop...Go..." etc, so when I use

ls=My.Computer.FileSystem.ReadAllText(Dialog1.File Name)
sqlCommand.CommandText = ls
sqlCommand.ExecuteNonQuery()
I got many syntex error. (such as "Go" should be the last). I set the
command type to "text". I don't know what method I should use to read
string from the file and how should I tell sqlCommand that this is SQL
Script and not normal SQL Statement.

Thanks again
Leanne

Cor Ligthert [MVP] wrote:
Leanne,

You can run every script using the SQLCommand.executenonquery, therefore as
well Create and Alter statements.

http://msdn2.microsoft.com/en-us/lib...enonquery.aspx

I hope this helps,

Cor
"Leanne" <le******@connectretail.com.auschreef in bericht
news:11**********************@f16g2000cwb.googlegr oups.com...
I am doing customization for Microsoft Pos. I am working on
installation package now. I added some new tables and stored
procuedures and generated SQL Script for that. During the installation
process, after user entered the server name and database name, how to
open the script file (*.sql) and run that to update database? So they
don't have to open Query Analizer to run it. The idea is to get
everything done during the installation process. Anyone got an idea?

Thanks in advance.

Leanne
Nov 9 '06 #3

P: n/a
Leanne,

Did you look at the code in the Query analyzer from the SQL management tool,
if you start with a new one, than that starts with statements to let it
execute to be imported in the program libraries of SQL server.

Cor

"Leanne" <le******@connectretail.com.auschreef in bericht
news:11*********************@h48g2000cwc.googlegro ups.com...
Cor,
Thank you for your reply. My problem is, the generated SQL script
contains a lot " if exist...then drop...Go..." etc, so when I use

ls=My.Computer.FileSystem.ReadAllText(Dialog1.File Name)
sqlCommand.CommandText = ls
sqlCommand.ExecuteNonQuery()
I got many syntex error. (such as "Go" should be the last). I set the
command type to "text". I don't know what method I should use to read
string from the file and how should I tell sqlCommand that this is SQL
Script and not normal SQL Statement.

Thanks again
Leanne

Cor Ligthert [MVP] wrote:
>Leanne,

You can run every script using the SQLCommand.executenonquery, therefore
as
well Create and Alter statements.

http://msdn2.microsoft.com/en-us/lib...enonquery.aspx

I hope this helps,

Cor
"Leanne" <le******@connectretail.com.auschreef in bericht
news:11**********************@f16g2000cwb.googleg roups.com...
>I am doing customization for Microsoft Pos. I am working on
installation package now. I added some new tables and stored
procuedures and generated SQL Script for that. During the installation
process, after user entered the server name and database name, how to
open the script file (*.sql) and run that to update database? So they
don't have to open Query Analizer to run it. The idea is to get
everything done during the installation process. Anyone got an idea?

Thanks in advance.

Leanne

Nov 9 '06 #4

P: n/a
Cor,

If I start Query analyzer, then open the sql file, I can run that
without any problem.
Now what I want is to open the sql file from VB, and then execute that
throuth sqlCommand. Can you tell me how to do that? Some code sample
maybe?

Thanks
Leanne

Cor Ligthert [MVP] wrote:
Leanne,

Did you look at the code in the Query analyzer from the SQL management tool,
if you start with a new one, than that starts with statements to let it
execute to be imported in the program libraries of SQL server.

Cor

"Leanne" <le******@connectretail.com.auschreef in bericht
news:11*********************@h48g2000cwc.googlegro ups.com...
Cor,
Thank you for your reply. My problem is, the generated SQL script
contains a lot " if exist...then drop...Go..." etc, so when I use

ls=My.Computer.FileSystem.ReadAllText(Dialog1.File Name)
sqlCommand.CommandText = ls
sqlCommand.ExecuteNonQuery()
I got many syntex error. (such as "Go" should be the last). I set the
command type to "text". I don't know what method I should use to read
string from the file and how should I tell sqlCommand that this is SQL
Script and not normal SQL Statement.

Thanks again
Leanne

Cor Ligthert [MVP] wrote:
Leanne,

You can run every script using the SQLCommand.executenonquery, therefore
as
well Create and Alter statements.

http://msdn2.microsoft.com/en-us/lib...enonquery.aspx

I hope this helps,

Cor
"Leanne" <le******@connectretail.com.auschreef in bericht
news:11**********************@f16g2000cwb.googlegr oups.com...
I am doing customization for Microsoft Pos. I am working on
installation package now. I added some new tables and stored
procuedures and generated SQL Script for that. During the installation
process, after user entered the server name and database name, how to
open the script file (*.sql) and run that to update database? So they
don't have to open Query Analizer to run it. The idea is to get
everything done during the installation process. Anyone got an idea?

Thanks in advance.

Leanne
Nov 9 '06 #5

P: n/a
Not tested,

cmd.CommandText = _
"CREATE PROCEDURE dbo.whatever AS & vbCrLf & _
SELECT * FROM MyTable"
cmd.ExecuteNonQuery()

If it is already in your database than CREATE is ALTER

I hope this helps,

Cor

"Leanne" <le******@connectretail.com.auschreef in bericht
news:11**********************@i42g2000cwa.googlegr oups.com...
Cor,

If I start Query analyzer, then open the sql file, I can run that
without any problem.
Now what I want is to open the sql file from VB, and then execute that
throuth sqlCommand. Can you tell me how to do that? Some code sample
maybe?

Thanks
Leanne

Cor Ligthert [MVP] wrote:
>Leanne,

Did you look at the code in the Query analyzer from the SQL management
tool,
if you start with a new one, than that starts with statements to let it
execute to be imported in the program libraries of SQL server.

Cor

"Leanne" <le******@connectretail.com.auschreef in bericht
news:11*********************@h48g2000cwc.googlegr oups.com...
Cor,
Thank you for your reply. My problem is, the generated SQL script
contains a lot " if exist...then drop...Go..." etc, so when I use

ls=My.Computer.FileSystem.ReadAllText(Dialog1.File Name)
sqlCommand.CommandText = ls
sqlCommand.ExecuteNonQuery()
I got many syntex error. (such as "Go" should be the last). I set the
command type to "text". I don't know what method I should use to read
string from the file and how should I tell sqlCommand that this is SQL
Script and not normal SQL Statement.

Thanks again
Leanne

Cor Ligthert [MVP] wrote:
Leanne,

You can run every script using the SQLCommand.executenonquery,
therefore
as
well Create and Alter statements.

http://msdn2.microsoft.com/en-us/lib...enonquery.aspx

I hope this helps,

Cor
"Leanne" <le******@connectretail.com.auschreef in bericht
news:11**********************@f16g2000cwb.googleg roups.com...
I am doing customization for Microsoft Pos. I am working on
installation package now. I added some new tables and stored
procuedures and generated SQL Script for that. During the
installation
process, after user entered the server name and database name, how
to
open the script file (*.sql) and run that to update database? So
they
don't have to open Query Analizer to run it. The idea is to get
everything done during the installation process. Anyone got an idea?

Thanks in advance.

Leanne


Nov 10 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.