Showing posts with label scripts. Show all posts
Showing posts with label scripts. Show all posts

Sunday, March 25, 2012

Deployment 'utility' script using sqlcmd

Hi all,
I'm looking at creating a sample utility script that will invoking scripts to deploy some SQL code. For example, a utlity script that will run a SQL script, and on successful completion, execute the next script.
Having not used SQLCMD at all before, and being very new to SQL2005 (< 1 month) please guide me if there is a better way of invoking this... For example, a way of avoiding the xp_cmdshell invocation!
The following code invokes a script, but I'm trying to find a way of getting a return code back from sqlcmd, so I can progress and do the next, or fail if the return code <> 0 (success).
[code]
--Process to create DB, Tables, and Stored Procedures
set nocount on
DECLARE
@.Error int,
@.ExecCommand varchar(512),
@.FullFilePath varchar(255)
--create the database
BEGIN TRY
SET @.FullFilePath = 'D:\Documentation\Projects\Integration Services\BIDS Projects\Tesco DNF Integration Services\TescoDNF ProductPromo\SQL Code\OBJECTS\Create DB TescoDNF_SSISPackageManager.sql'
SET @.ExecCommand = 'xp_cmdshell ''sqlcmd -S Rgalbraith\SQL2005_1 -i "'+@.FullFilePath+'"'' '
SELECT @.FullFilePath
UNION
SELECT @.ExecCommand
EXEC (@.ExecCommand)
SELECT @.@.ERROR
SELECT @.Error
END TRY
BEGIN CATCH
SELECT
ERROR_NUMBER() AS ErrorNumber,
ERROR_SEVERITY() AS ErrorSeverity,
ERROR_STATE() AS ErrorState,
ERROR_PROCEDURE() AS ErrorProcedure,
ERROR_LINE() AS ErrorLine,
ERROR_MESSAGE() AS ErrorMessage;
GOTO ErrorAbort
END CATCH

ErrorAbort:
[/code]

Hello
I didn't quite understand what are you trying to achieve. You have some sequence of sql scripts that need to be executed against a server one after another, if no error occurs?
Then, what if an error occurs? Maybe there is some branching in the scripts? I.e. if script1.sql succeedes, then execute script2.sql, else execute script3.sql. If script3.sql fails, restore a database backup...
And why are you doing this from SQL? Isn't using a programming language more effective?

|||My thought had been to have a simple T-SQL script that 'deploys' a set of SQL scripts to, for example, a server. For example, some pseudo-code
Create Database
If Error abort
Create Table1
If Error abort
Create Table2
If Error Abort
Create Stored Procedure1
If Error Abort
ELSE Complete and report success
I do agree that this is something that could be (better) done in a "proper" coding language like .Net, c# etc. but (a) it's just a simple utility script (b) it teaches me moore about usage of SQLCMD and (c) I do not have any skill in any normal programming language, hence I was planning to write a quick deployment utility with a script.
The idea might be something as ugly as a table structure that has a list of scripts registered in it, with some sequence logic - like creating parent tables before children tables - and then a cursor (or a better method if I can find it) that fetches a sqlcmd filename execution command, executes it, and on success fetches the next one based on the sequence logic.
I can probably do all of that in about 4 hours in T-SQL, if I can find a way to confirm the successful execution of the previous command....
|||

Ok I got it.
You can have a "Version" table, then number your scripts so that each of them updates the version. Before executing each portion of code, you can check the current version to be exactly the number you need.
e.g.
Create Database
Create table Version(VersionNum varchar(255), ChangeID int)
insert into Version(VersionNum, ChanegeID) values("1", @.ID)
GO
If (select VersionNum where ChangeID=@.ID)="1"
BEGIN
Create Table1
Update Version set VersionNum = "2" where ChangeID=@.ID
END
GO
If (select VersionNum where ChangeID=@.ID)="2"
...
So, basicly you just update the version number as the last command of each batch. Then, you check for the appropriate version number at the beginning of the next block.
This way you can even do some "branching". Even more, if your scripts fails, you can check what scripts have succeeded and what scripts have not, simply by looking at the VersionNo field.

Anyhow, I'd strongly reccomend using ordinal programming language if you are going to use that utility more than once and it MIGHT become somehow complicated.

|||Well, in a sense. The point is though that I want to fetch sql files and execute them, and not merge them all into a single large script.
So, I want utility script to do this:
Run external sql script
On failure abort, on Success
Run external sql script
On Failure abort, On Success
...
You being to see why I referred to a cursor?
The point is that the utility script wouldn't contain any of the client SQL commands - it would fetch them by referring to the table, and fetching the path to the SQL file, and building a SQLCMD to execute that script
I guess, as you say, I could add a generic update ##SQLScriptTracker table, then check it on the new execution, or abort. I had hoped for a neater solution - i.e. SQLCMD being able to return a returncode that it gets from a SQL file it ran....
|||

Why dont go for Batch files (.bat). There you can execute the individual script files one by one using the SQLCMD. And for aborting when error occurs, check the ERRORLEVEL, if its not 0 then quit execution or skip to other location using GOTO.

echo Backup database
sqlcmd -S(local) -U<uid> -P<pwd> -i"backup_db.sql"
IF ERRORLEVEL 1 GOTO abort_bkp

echo Update database
sqlcmd -S(local) -U<uid> -P<pwd> -i"create_proc.sql"
IF ERRORLEVEL 1 GOTO abort

echo Update customer data
sqlcmd -S(local) -U<uid> -P<pwd> -i"update_customer_data.sql"
IF ERRORLEVEL 1 GOTO abort_with_restore

:abort_bkp
echo Error backup database. Setup aborted

:abort_with_restore
echo Error updating data. Restoring database...
sqlcmd -S(local) -U<uid> -P<pwd> -i"restore_db.sql"
IF ERRORLEVEL 1 GOTO res_falied
...
...

|||

hmm ... it seems as thought ERRORLEVEL is only set on the SUCCESS/FAILURE of the SQLCMD invocation, and not based on the SUCCESS/FAILURE of the invoked sql commands?

for example:

batch CALLBACKUP.BAT file contents:

echo Backup database
sqlcmd -SRGalbraith\SQL2005_1 -E -i"d:\backup_db.sql"
IF ERRORLEVEL 1 GOTO abort_bkp
IF ERRORLEVEL 0 GOTO done

:abort_bkp
echo Error backup database. Setup aborted

:done
echo all done now

backup_db.sql contents

backup database DataStore2 to disk = 'D:\BackupDatabase.bak'

execution results:

D:\>sqlcmd -SRGalbraith\SQL2005_1 -E -i"d:\backup_db.sql"
Msg 911, Level 16, State 11, Server RGALBRAITH\SQL2005_1, Line 1
Could not locate entry in sysdatabases for database 'DataStore2'. No entry found with that name. Make sure that the name
is entered correctly.
Msg 3013, Level 16, State 1, Server RGALBRAITH\SQL2005_1, Line 1
BACKUP DATABASE is terminating abnormally.

D:\>IF ERRORLEVEL 1 GOTO abort_bkp

D:\>IF ERRORLEVEL 0 GOTO done

D:\>echo all done now
all done now

A sample of sqlcmd failing was:

D:\>callbackup

D:\>echo Backup database
Backup database

D:\>sqlcmd -SRGalbraith\SQL2005_1 -E -i"d:\backup_db.sql"
Sqlcmd: 'd:\backup_db.sql': Invalid filename.

D:\>IF ERRORLEVEL 1 GOTO abort_bkp

D:\>echo Error backup database. Setup aborted
Error backup database. Setup aborted

D:\>echo all done now
all done now

...

As is probably obvious, I'm not much of a batch file coder :-), but the jmist of it is there - when the SQLCMD failed (file not found) then it reported error, but when the SQL script failed (database not found) no error was reported. Is there a way around that?

|||

You have to set the -b option for the SQLCMD. -b makes the batch abort with an error if the script fails. So you would write this...

@.ECHO OFF

@.echo.
@.echo Backup database
sqlcmd -S.\sqlexpress -E -i"backup_db.sql" -b
IF %ERRORLEVEL% NEQ 0 GOTO err_bkp_failed

:success
echo Database update successful
goto end

:err_bkp_failed
echo Backup failed. Aborting...
goto end

:end

HTH

|||hmm - good to know! still going to investiage the other options as well, since with the batch file I have to add a file each time.
Thanks
|||

Visual Studio .Net 2003 had a "create batch file" command which was beautiful for creating this batch file to process the sequence of sql scripts that you create.

I still use it today. But it seems we are in need to migrate to Visual Studio 2005, and this feature has been disabled now.

Do you have a more elegant solution now?

|||

Actually you don't have to modifiy the bat script each time. I have been using bat scripts to do exactly this for years.

The shell support the For Each looping structure which will set a shell variable to each file name that meet's a spec.

For Each %%1 in *.sql <execute a dos command>

I have been using the OSQL command line utility for years like this. I guess I will have to update to SQLCMD now.

You can find out the details of shell commands by going to "My Computer" <Help> and searching for "For Each"

You can find out about OSQL in BOL

|||

I've been searching solution on catching MS SQL abortion errors in a launching batch file. With option '-b', at least the batch file could return error code 1 instead of 0. Thanks for the hint!

Still, I'd appreciate if anyone could offer answer on capturing the stdout error in the batch file. My problem is that once the sql statement is aborted, it immediately exits from the erroneous line, ignores the rest code in the same script. Therefore, no error could be saved.

Also, I found that in some env. the 'sqlcmd' is not recognized (SQL Server 2000?) but 'osql' or 'isql'. Are there any differences among them (must be, but I don't know).

sql

Thursday, March 22, 2012

Deployment Scripts

We are introducing a new infrastructure in work where we use depoyment
scripts rather than tweaking the db with Enterprise Manager. While I can see
the benefits of this it will be time consuming. Are there any tools out
there to automatically generate any kind of DDL script you would want. For
instance I can't find a way in Enterprise Manager/ Query Analyser to
generate logins or stuff related to jobs. Regards, Chris.Chris,
to generate logins, there is the Options tab on the Generate SQL Scripts
dialogue. For jobs, just highlight them all and right-click.
There are other things that aren't scriptable though from the GUI (linked
servers, maintenance plans, diagrams etc). For these I know of workarounds
but no simple tool. BTW in SQL Server 2005 almost anything is scriptable
from the GUI.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com|||Chris wrote:
> We are introducing a new infrastructure in work where we use depoyment
> scripts rather than tweaking the db with Enterprise Manager. While I can s
ee
> the benefits of this it will be time consuming. Are there any tools out
> there to automatically generate any kind of DDL script you would want. For
> instance I can't find a way in Enterprise Manager/ Query Analyser to
> generate logins or stuff related to jobs. Regards, Chris.
>
Kudos to whoever is driving this change. It may seem time consuming
now, but after you get used to it, you'll find that the GUI is actually
harder to use than writing the scripts.
While some things may not be directly scriptable from Enterprise
Manager, virtually EVERYTHING that EM does can be done using scripts,
you just have to learn the commands. One way to observe what goes on
under the covers is to use Profiler to capture the commands issued by EM
when performing various operations.
Tracy McKibben
MCDBA
http://www.realsqlguy.comsql

Deployment Scripts

We are introducing a new infrastructure in work where we use depoyment
scripts rather than tweaking the db with Enterprise Manager. While I can see
the benefits of this it will be time consuming. Are there any tools out
there to automatically generate any kind of DDL script you would want. For
instance I can't find a way in Enterprise Manager/ Query Analyser to
generate logins or stuff related to jobs. Regards, Chris.Chris,
to generate logins, there is the Options tab on the Generate SQL Scripts
dialogue. For jobs, just highlight them all and right-click.
There are other things that aren't scriptable though from the GUI (linked
servers, maintenance plans, diagrams etc). For these I know of workarounds
but no simple tool. BTW in SQL Server 2005 almost anything is scriptable
from the GUI.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com|||Chris wrote:
> We are introducing a new infrastructure in work where we use depoyment
> scripts rather than tweaking the db with Enterprise Manager. While I can see
> the benefits of this it will be time consuming. Are there any tools out
> there to automatically generate any kind of DDL script you would want. For
> instance I can't find a way in Enterprise Manager/ Query Analyser to
> generate logins or stuff related to jobs. Regards, Chris.
>
Kudos to whoever is driving this change. It may seem time consuming
now, but after you get used to it, you'll find that the GUI is actually
harder to use than writing the scripts.
While some things may not be directly scriptable from Enterprise
Manager, virtually EVERYTHING that EM does can be done using scripts,
you just have to learn the commands. One way to observe what goes on
under the covers is to use Profiler to capture the commands issued by EM
when performing various operations.
Tracy McKibben
MCDBA
http://www.realsqlguy.com

Wednesday, March 21, 2012

Deployment

Hello,
What is the best way to deploy a Reporting Services solution. The solution
consists of database scripts, reports, CRI dll's and roles.
Thanks
HenrikHello Henrik,
I am not sure what does your solution include.
Based on my research and experience, you need to deploy those data
seperately.
For example, you need to run all the database scripts on the production
environment and then, you could use the VS 2005 IDE to deploy the report.
I am not sure what did you mean CRI dll and roles. Would you please specify
it more clearly?
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================(This posting is provided "AS IS", with no warranties, and confers no
rights.)|||Hello Wei Lu,
We have a solution that contains the following elements:
1) SQL Scripts, which create views, tables, ect.
2) Custom Report Items (CRI) which is contained in a DLL
3) Reports (RDL files)
4) Reporting Services User Roles
5) Datasources
6) Setup of policies (permissions) on each report
We have to package the solution and deploy it to multiple customers.
Best regards
Henrik.
"Wei Lu [MSFT]" <weilu@.online.microsoft.com> wrote in message
news:OnGVeBD7GHA.2336@.TK2MSFTNGXA01.phx.gbl...
> Hello Henrik,
> I am not sure what does your solution include.
> Based on my research and experience, you need to deploy those data
> seperately.
> For example, you need to run all the database scripts on the production
> environment and then, you could use the VS 2005 IDE to deploy the report.
> I am not sure what did you mean CRI dll and roles. Would you please
> specify
> it more clearly?
> Sincerely,
> Wei Lu
> Microsoft Online Community Support
> ==================================================> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications.
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/default.aspx.
> ==================================================> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>|||Have you looked at MSI packages?
You could probably package most of the elements. MSI packages can be used
for SQL scripts, which covers element 1, and might cover element 4, 5 and 6
if you can do this through SQL. It can also install dlls, covering element
2. I've never tried using msi against a web service, but it should be
possible, and with the right setup of your package, you should be able to
either deploy your reports or at least trigger a rss-script (reporting
services script, not the blog rss :) ) that will deploy your reports.
A bit of information here
http://www.sqlmag.com/Article/ArticleID/22428/sql_server_22428.html
A more hands-on example and article here
http://www.csharp-home.com/index/tiki-read_article.php?articleId=152
If you decide on msi, please tell the NG what you do and how successful it
turns out.
Kaisa M. Lindahl Lervik
"Henrik Skak Pedersen" <skak@.community.nospam> wrote in message
news:eY0e8DE7GHA.4116@.TK2MSFTNGP03.phx.gbl...
> Hello Wei Lu,
> We have a solution that contains the following elements:
> 1) SQL Scripts, which create views, tables, ect.
> 2) Custom Report Items (CRI) which is contained in a DLL
> 3) Reports (RDL files)
> 4) Reporting Services User Roles
> 5) Datasources
> 6) Setup of policies (permissions) on each report
> We have to package the solution and deploy it to multiple customers.
> Best regards
> Henrik.
>
> "Wei Lu [MSFT]" <weilu@.online.microsoft.com> wrote in message
> news:OnGVeBD7GHA.2336@.TK2MSFTNGXA01.phx.gbl...
>> Hello Henrik,
>> I am not sure what does your solution include.
>> Based on my research and experience, you need to deploy those data
>> seperately.
>> For example, you need to run all the database scripts on the production
>> environment and then, you could use the VS 2005 IDE to deploy the report.
>> I am not sure what did you mean CRI dll and roles. Would you please
>> specify
>> it more clearly?
>> Sincerely,
>> Wei Lu
>> Microsoft Online Community Support
>> ==================================================>> Get notification to my posts through email? Please refer to
>> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
>> ications.
>> Note: The MSDN Managed Newsgroup support offering is for non-urgent
>> issues
>> where an initial response from the community or a Microsoft Support
>> Engineer within 1 business day is acceptable. Please note that each
>> follow
>> up response may take approximately 2 business days as the support
>> professional working with you may need further investigation to reach the
>> most efficient resolution. The offering is not appropriate for situations
>> that require urgent, real-time or phone-based interactions or complex
>> project analysis and dump analysis issues. Issues of this nature are best
>> handled working with a dedicated Microsoft Support Engineer by contacting
>> Microsoft Customer Support Services (CSS) at
>> http://msdn.microsoft.com/subscriptions/support/default.aspx.
>> ==================================================>> (This posting is provided "AS IS", with no warranties, and confers no
>> rights.)
>|||Hello Henrik,
I agreee with Kaisa.
You could setup a MSI package to deploy the SQL Script and use the RSS
script to deploy the Report.
Here are also some article for your reference:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/ht
ml/vbtskcreatinginstallerforyourapplication.asp
http://www.codeproject.com/dotnet/Win_App_Setup_Project.asp?df=100&forumid=2
50630&exp=0&select=1419048
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/rsprog/htm/
rsp_prog_soapapi_script_3ik1.asp
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Hi ,
How is everything going? Please feel free to let me know if you need any
assistance.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.

Sunday, March 11, 2012

Deploying Scripts to Multiple SQL Server Instances

Hello everyone,
I work for a software development company that has over 20 MSSQL2000
developer and support instances/environments in which I frequently
apply incremental updates to. The updates are SQL scripts given to me
by developers that, for example, add columns, drop and create updated
or new stored procedures or views. Sometimes a specific version of our
software may have 15-20 incremental updates to deploy. These updates
need to be applied somewhat immediatly to most of the data instances.
I've been running these manually for quite sometime via SQL Query
Analizer. In case you are wondering, as for applying permissions to
these objects, I've already got a script that sets permissions for
specified users for specified databases that i can run for each
instance in the click of a mouse.
What I am longing for is some sort of utility that may exist out there
for doing exactly what I am doing with these incremental updates, yet
more automated. We name our scripts specifically so that they can be
thrown into a single folder and they are already sorted by date and
type, so that a stored procedure update won't reference a table update
that has not been applied yet, etc.
Anyone have any directions they could point me in? I've tried
searching the newsgroups and net with no luck so far.This is a multi-part message in MIME format.
--=_NextPart_000_02AB_01C3AD1B.1AEF2BB0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Check out "master server" in the BOL.
--
Tom
---
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
"Matt Norwood" <littletinymonkey@.hotmail.com> wrote in message
news:cc80cca0.0311171148.7e43bcff@.posting.google.com...
Hello everyone,
I work for a software development company that has over 20 MSSQL2000
developer and support instances/environments in which I frequently
apply incremental updates to. The updates are SQL scripts given to me
by developers that, for example, add columns, drop and create updated
or new stored procedures or views. Sometimes a specific version of our
software may have 15-20 incremental updates to deploy. These updates
need to be applied somewhat immediatly to most of the data instances.
I've been running these manually for quite sometime via SQL Query
Analizer. In case you are wondering, as for applying permissions to
these objects, I've already got a script that sets permissions for
specified users for specified databases that i can run for each
instance in the click of a mouse.
What I am longing for is some sort of utility that may exist out there
for doing exactly what I am doing with these incremental updates, yet
more automated. We name our scripts specifically so that they can be
thrown into a single folder and they are already sorted by date and
type, so that a stored procedure update won't reference a table update
that has not been applied yet, etc.
Anyone have any directions they could point me in? I've tried
searching the newsgroups and net with no luck so far.
--=_NextPart_000_02AB_01C3AD1B.1AEF2BB0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&

Check out "master server" in the =BOL.
-- Tom
---T=homas A. Moreau, BSc, PhD, MCSE, MCDBASQL Server MVPColumnist, SQL =Server ProfessionalToronto, ON Canadahttp://www.pinnaclepublishing.com/sql">www.pinnaclepublishing.com=/sql
"Matt Norwood" wrote in message news:cc80cc=a0.0311171148.7e43bcff@.posting.google.com...Hello everyone,I work for a software development company that has over =20 MSSQL2000developer and support instances/environments in which I frequentlyapply incremental updates to. The updates are SQL scripts =given to meby developers that, for example, add columns, drop and create updatedor new stored procedures or views. Sometimes a specific =version of oursoftware may have 15-20 incremental updates to deploy. These updatesneed to be applied somewhat immediatly to most of the data instances.I've been running these manually for quite sometime via =SQL QueryAnalizer. In case you are wondering, as for applying =permissions tothese objects, I've already got a script that sets permissions forspecified users for specified databases that i can run for eachinstance in the click of a mouse.What I am longing for =is some sort of utility that may exist out therefor doing exactly what I am =doing with these incremental updates, yetmore automated. We name our =scripts specifically so that they can bethrown into a single folder and they =are already sorted by date andtype, so that a stored procedure update =won't reference a table updatethat has not been applied yet, =etc.Anyone have any directions they could point me in? I've triedsearching the newsgroups and net with no luck so far.

--=_NextPart_000_02AB_01C3AD1B.1AEF2BB0--|||have a read on www.dbghost.com it may be the help you need.
>--Original Message--
>Check out "master server" in the BOL.
>--
>Tom
>----
--
>Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
>SQL Server MVP
>Columnist, SQL Server Professional
>Toronto, ON Canada
>www.pinnaclepublishing.com/sql
>
>"Matt Norwood" <littletinymonkey@.hotmail.com> wrote in
message
>news:cc80cca0.0311171148.7e43bcff@.posting.google.com...
>Hello everyone,
>I work for a software development company that has over
20 MSSQL2000
>developer and support instances/environments in which I
frequently
>apply incremental updates to. The updates are SQL scripts
given to me
>by developers that, for example, add columns, drop and
create updated
>or new stored procedures or views. Sometimes a specific
version of our
>software may have 15-20 incremental updates to deploy.
These updates
>need to be applied somewhat immediatly to most of the
data instances.
>I've been running these manually for quite sometime via
SQL Query
>Analizer. In case you are wondering, as for applying
permissions to
>these objects, I've already got a script that sets
permissions for
>specified users for specified databases that i can run
for each
>instance in the click of a mouse.
>What I am longing for is some sort of utility that may
exist out there
>for doing exactly what I am doing with these incremental
updates, yet
>more automated. We name our scripts specifically so that
they can be
>thrown into a single folder and they are already sorted
by date and
>type, so that a stored procedure update won't reference a
table update
>that has not been applied yet, etc.
>Anyone have any directions they could point me in? I've
tried
>searching the newsgroups and net with no luck so far.
>|||thanks!

Wednesday, March 7, 2012

Deploying a full database through XMLA and C#

Hi all,

I want to create , deploy and process the XMLA scripts for a full projectin SSAS . I want to do this through code C#. I have the XMLA's. I want the code to check wether the database exists and tehn drop it if it exists and create a new database , create and deploy and process the DSV, cubes and other objects one by one taking the XMLA. I also want to capture the log as to what happened , i mean wether it was sucessful or it threw an error.

Please give me some sample code as to how to go about it...

Regards...

Girija Shankar

Hi,

You can use AMO to check if the database exist, to drop it, to re-create it, to run XMLA scripts.

Sample code for running XMLA scripts with AMO:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=516930&SiteID=1

You mentioned that you want to drop the database if it exists and then re-create it. You can do that in a single step, the 'Create' command has the 'AllowOverwrite' parameter:

<Create AllowOverwrite='true'>

... the database definition here ...

</Create>

Adrian Dumitrascu

|||Hi Adrian,

Thanks for the answer. But I think you didnot get my question. I want to check in the server wether the database exists or not. if it exists i will drop that and take the xmla script from a specified location as a xmla file and then process it to cretae the necessary objects. then i process the cubes present in the Database one by one. Now the point is how do i check wether it exists and i want to catch the processing results ( wether success or failure). The XMLA will be a predifined file existing on local system.

Regards....
Girija Shankar

Saturday, February 25, 2012

deploying a database

what is the easiest way to deploy a database for a webapp? i have create table scripts but waht is the easiest way to go about inserting data into lookup tables? would i have to write insert statements or is there some other way to do it

I use two different methods when I create lookup tables.

1) Manually type into the table the data

2) Create a script file which I run in query analyzer. Here is a sample of one the scripts I write:

create table [tbl_LookupCategory]

([int_CategoryID] int NOT NULL Primary Key,
[str_Category] nvarchar(20) Not NULL)

/* Insert the data into the table */

INSERT INTO [tbl_LookupCategory]
( [int_CategoryID],
[str_Category]
)


VALUES
( 1, 'Shirt' )

INSERT INTO [tbl_LookupCategory]
( [int_CategoryID],
[str_Category]
)
VALUES
( 2, 'Hat' )

|||

You can also use copy database wizard to copy your database to other servers.

Sunday, February 19, 2012

Deploy CLR SQL Project using MSBuild

What is the "official" line on deploying CLR SQL projects through the use of build scripts like NANT and MSBuild?

I'm obviously keen to hook up my project to my continuous integration build but the only things I have found that touch on the subject are:

    Do it by hand yourself using xcopy of assemblies and T-SQL

    Use SQLCLR project

    This old post that says what *might* happen

Cheers

I don't really understand your question; are you asking what MS says about using NANT/MSBUILD for deployment - or are you asking what the community thinks?

Anyway, if your aim is to automate your deployment, and continuous build my preferences would be:
1. scripting
or
2. SQLCLR project (I would say that as I am the developer)

I would not use the VS built in SQL Server project type, as I feel I do not have the control as I would like.

Niels