Need Help With Update Database through Scripts

Hello, I am using the wyBUild for my app,we have SQL database used in our app. My concern is to Update the Database using the sql scripts. I read in one of the article that I can inlcude the sql scripts and the batch file in Temporary folder and that will be executed. Few things I am not clear about.1. The syntax in batchfile. - Below is the sample syntax I think should be for executing the script.sqlcmd -S MyServerName -i ..Path\TestSQLCMD.sql

Problem: What Path I should add here after -i.As it has to be some physical path I am guessing.

2.How will it actually update the Database.3.Again the path if its of the applications folder then, it will be different for a 32 Bit and the 64 Bit as in 64 Bit machine the App gets installed in Program Files (x86) folder as compare to Program Files for a 32 Bit machine.

Any ideas...

Thank You,Nirav

Problem: What Path I should add here after -i.As it has to be some physical path I am guessing.

It doesn't need to be a full path. If you're including the bat and the *sql files in the same folder in the Temp directory then simply specify the filename. E.g. sqlcmd -S MyServerName -i TestSQLCMD.sql

2.How will it actually update the Database.

I'm not sure I understand this question? Sqlcmd executes your SQL script which has SQL queries to update/change/delete databased. See sqlcmd Utility.

3.Again the path if its of the applications folder then, it will be different for a 32 Bit and the 64 Bit as in 64 Bit machine the App gets installed in Program Files (x86) folder as compare to Program Files for a 32 Bit machine.

I don't use sqlcmd, however isn't the executable defined in PATH? That is, if you type "sqlcmd" in a command window isn't sqlcmd run? That is, you don't need to specify the full path.

Hi Sam,

Thanks a Lot for a quick and explanatory reply, so thats clear now that I dont need to include any path, and also I can see that it would use cmd to execute the db. I had tried to create a batch file and sql file and created a update to my app, as suggested I included both the files in temp folder and on batch file selected execute check box as well.

So now When I tested the update on one of other machine where my app is already installed, it seems that it opened cmd to execute the script(Cmd was open for few fractions of sec so I could not read any thing) but what I see after the app restarted is a red crossing which says that

"C:\Users\Nirav\wc\9\temp\MyBatchFile.bat" returned 1.

Thanks

This means the batch file failed to execute. If I were you I would test the batch file before including it in the update. That is, just run it first to see what's failing. Once you have that figured out, then include it in your updates.

Hi Sam,

I had done it already..when I double click and run the batch file directly..it works fine..I mean it executes successfully without errors. In script I had created dummy procedure when I execute batch file it creates that procedure.

Thanks

Any Ideas...I am stucked here

Thanks

Send me your wyBuild project to support@wyday.com. Also include the bat file and the sql file.

HI Sam,

I had emailed the project.

Thanks

HI Sam,

Thanks a lot for all your support, I finally get it to work using %0. And we had bought the wyBUild. We are happy that is all working smoothly now.

Thanks & Regards

Nirav

Hi there,I have a same problem. How did you fix the problem?

Thanks you,Peter

You can get the bat file's current full directory by using %0 in the batch script. So this...

%0\..\YourSQLScript.sql

in a batch file would reference the "YourSQLScript.sql" SQL script in the same folder as the batch file. Obviously you'd wrap that in quotes if there are any spaces in the path (like in the batch file name or the script name).

Tell me if this helps.

Hi,

I am new to update sql scripts with wyupdate

Could you kindly give me example file for sql scripts updation?

how to create sql batch file and include in wyupdate?

could you give step by step instructions to update database sql scripts

Thanks, i put the script and batch file in the same location and executed successfully.i have to create that batch file dynamically. Because the server name, database name will be different . How can i do this?

Hi same error

"C:\Users\Anand\wc\5\temp\Batch.bat" returned 1."

my batch contentsqlcmd -U sa -P test -S SS103 -d testDB -i %0\..\prUserMasterSel.sql>>"Result.Log"exit /B %ERRORLEVEL%

simple dummy procedure (prUserMasterSel)

please help

I don't know -- there's not nearly enough information. Try looking in the result log to see the results of the query.

Try running this in a console window first, make sure everything works, then (and only then) include it as part of your update.