Showing posts with label control. Show all posts
Showing posts with label control. Show all posts

Wednesday, March 28, 2012

Script to reverse engineering schema

Hi,

I'd like to reverse engineer the schema definitions in the SQL Server
on a daily basis and store them in a version control system.

Could anyone please let know if there are any tools to reverse engineer
the entire schema definitions in the SQL server. I'd like something
like the perl script 'dbschema.pl' for the Sybase ASE.

Regards,
Dellit.Thyagu (tdelli@.gmail.com) writes:
> I'd like to reverse engineer the schema definitions in the SQL Server
> on a daily basis and store them in a version control system.

Sounds like the wrong way to do. Would you version-control your C++
code by disassembling every day?

> Could anyone please let know if there are any tools to reverse engineer
> the entire schema definitions in the SQL server. I'd like something
> like the perl script 'dbschema.pl' for the Sybase ASE.

Look at SQL Compare from Red Gate and see if it could work for you.

You can always do it from Enterprise Manager, but that's tedious to do
on a daily basis. But you could investigate to see how much work it would
take to do this in DMO. Or SMO if you are on SQL 2005. (I have not used
any of them, so I cannot assist with the details.)
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Dellit,

If you objective is to keep track of changes over time, and use a
version control system to keep track of changes over time, you can use
SchemaCrawler, a free open-source tool that can compare schemas as well
as data.

SchemaCrawler is a command-line tool to output your database schema and
data in a readable form. The output is designed to be diff-ed with
previous versions of your database schema.

http://schemacrawler.sourceforge.net/

All you will need is a JDBC driver, and any diff tool such as WinMerge.

Sualeh Fatehi.|||I have a script that I use SCPTXFR in to check our database builds into
Visual Source Safe on a daily basis; it's actually very handy in a
development environment where you have multiple SQL developers poking
into each other's code.

DMO is nice, but I haven't figured out how to handle depndancies yet;
without that knowledge, the build script is ordered by table name,
which is not particularly useful when you are trying to rebuild a
database.

Stusql

Friday, March 23, 2012

Script to change all database object owners at one time

Hi:
Does any one know where I can find a script that will change ownership of
all database objects at once. I took over control of a large database and
changing owners using sp_changeobjectowner one at a time will take forever.
Thanks,
CharlieYou could use a cursor to retrieve the objects that you want to change
(tables, views, stored procedures, user defined functions...) and call
sp_changeobjectowner on each object.
You can find examples of cursors within Books Online.
Keith
"Charlie@.CBFC" <charle1@.comcast.net> wrote in message
news:ueFBZXyzFHA.2076@.TK2MSFTNGP14.phx.gbl...
> Hi:
> Does any one know where I can find a script that will change ownership of
> all database objects at once. I took over control of a large database and
> changing owners using sp_changeobjectowner one at a time will take
> forever.
> Thanks,
> Charlie
>|||Since this is a one time thing, look at the UNdocumented stored procedure
sp_MSforeachtable.
This will give you an idea on how to use it:
http://www.databasejournal.com/feat...cle.php/3441031
http://www.dbazine.com/sql/sql-articles/larsen5
"Charlie@.CBFC" <charle1@.comcast.net> wrote in message
news:ueFBZXyzFHA.2076@.TK2MSFTNGP14.phx.gbl...
> Hi:
> Does any one know where I can find a script that will change ownership of
> all database objects at once. I took over control of a large database and
> changing owners using sp_changeobjectowner one at a time will take
> forever.
> Thanks,
> Charlie
>|||This will generate the script for you for all user-defined views, tables,
stored procedures and functions that aren't already owned by dbo:
SELECT 'EXEC sp_changeobjectowner
'''+TABLE_SCHEMA+'.'+TABLE_NAME+''',''dbo'''
FROM INFORMATION_SCHEMA.TABLES
WHERE OBJECTPROPERTY(OBJECT_ID(TABLE_SCHEMA+'.'+TABLE_NAME),
'IsMsShipped')=0
AND TABLE_SCHEMA != 'dbo'
SELECT 'EXEC sp_changeobjectowner
'''+ROUTINE_SCHEMA+'.'+ROUTINE_NAME+''',''dbo'''
FROM INFORMATION_SCHEMA.ROUTINES
WHERE OBJECTPROPERTY(OBJECT_ID(ROUTINE_SCHEMA+
'.'+ROUTINE_NAME),
'IsMsShipped')=0
AND ROUTINE_SCHEMA != 'dbo'
You can copy the results to the top pane and execute. The only potential
issue is if you have a situation like this:
userA.tableFoo
dbo.tableFoo
Or
userA.tableFoo
userB.tableFoo
Because it will crap out when you try to force dbo to own two objects with
the same name...
"Charlie@.CBFC" <charle1@.comcast.net> wrote in message
news:ueFBZXyzFHA.2076@.TK2MSFTNGP14.phx.gbl...
> Hi:
> Does any one know where I can find a script that will change ownership of
> all database objects at once. I took over control of a large database and
> changing owners using sp_changeobjectowner one at a time will take
> forever.
> Thanks,
> Charlie
>|||Thanks!
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uTuvD0yzFHA.904@.tk2msftngp13.phx.gbl...
> This will generate the script for you for all user-defined views, tables,
> stored procedures and functions that aren't already owned by dbo:
> SELECT 'EXEC sp_changeobjectowner
> '''+TABLE_SCHEMA+'.'+TABLE_NAME+''',''dbo'''
> FROM INFORMATION_SCHEMA.TABLES
> WHERE OBJECTPROPERTY(OBJECT_ID(TABLE_SCHEMA+'.'+TABLE_NAME),
> 'IsMsShipped')=0
> AND TABLE_SCHEMA != 'dbo'
> SELECT 'EXEC sp_changeobjectowner
> '''+ROUTINE_SCHEMA+'.'+ROUTINE_NAME+''',''dbo'''
> FROM INFORMATION_SCHEMA.ROUTINES
> WHERE OBJECTPROPERTY(OBJECT_ID(ROUTINE_SCHEMA+
'.'+ROUTINE_NAME),
> 'IsMsShipped')=0
> AND ROUTINE_SCHEMA != 'dbo'
> You can copy the results to the top pane and execute. The only potential
> issue is if you have a situation like this:
> userA.tableFoo
> dbo.tableFoo
> Or
> userA.tableFoo
> userB.tableFoo
> Because it will crap out when you try to force dbo to own two objects with
> the same name...
>
>
> "Charlie@.CBFC" <charle1@.comcast.net> wrote in message
> news:ueFBZXyzFHA.2076@.TK2MSFTNGP14.phx.gbl...
of
and
>sql

Wednesday, March 21, 2012

Script task raising OnError Events

Is there a way I can stop a script task of a control flow from raising OnError Events? or Is there a way I can Set Dts.Results to Fail without having the script task raise OnError event.

The reason why I need to fail the task is because I am using Precedence constraints and by setting the status to Fail I can stop the control flow. However, this action raises OnError event. I expect onError event to be raised if there are any exceptions in the script not when the Results is changed to fail.

I have tried capturing the failure into a dummy script, however the OnError event is still raised.

Try putting the code that raises the error in a TRY...CATCH block, that'll stop individual lines of code from throwing errors.
I'm pretty sure though that if you set Dts.TaskResult = Dts.Results.Failure then it'll trigger an OnError event.

-Jamie

|||Failing a task is designed for signalling an error,
and should not be used to drive regular (non
exceptional) control flow.

To alter control flow, a better solution is using
conditions on precedence contraints instead.

You can set some variable in the script task, then
add on-success or on-completed precedence constraint
with condition that checks that variable.

Hope this helps,
Michael [SSIS Technical Lead]|||There are better ways to stop the task without returning failure result from the script task. For example, you could have an expression on the precedence constraint that checks a variable value you set in the script for whether to go on or not.
Try that, it will solve both problems I think.
K|||I have tried setting expressions within precedence constraint and it works. But I find setting variable and changing variable's value little kludge and I am surprised that Script Task does not have a property that will fail precedence constraint without raising an error.

On the contrary end, I guess it makes sense to have script task raise an error if I set it to failure manually, since all the other tasks have similiar behaviour. That is if they fail they raise OnError event.

Thanks everyone.|||

Do you want to force a failure result without actually throwing an error? If so try the ForceExecutionResult property. It is a container property, so available on all tasks.

|||

Hi

I think ive got a similar problem.

We have set up an SSIS package which goes to an FTP site and downloads files.

Everything is fine... EXCEPT (lol) when there are no files to download. This then fails the task.

However, I want the package to continue to run.

Is there away of assigning the error message given to an expression and then using the expression in the precedence contraint?

thanking you in advance

David

sql

Script task raising OnError Events

Is there a way I can stop a script task of a control flow from raising OnError Events? or Is there a way I can Set Dts.Results to Fail without having the script task raise OnError event.

The reason why I need to fail the task is because I am using Precedence constraints and by setting the status to Fail I can stop the control flow. However, this action raises OnError event. I expect onError event to be raised if there are any exceptions in the script not when the Results is changed to fail.

I have tried capturing the failure into a dummy script, however the OnError event is still raised.

Try putting the code that raises the error in a TRY...CATCH block, that'll stop individual lines of code from throwing errors.
I'm pretty sure though that if you set Dts.TaskResult = Dts.Results.Failure then it'll trigger an OnError event.

-Jamie

|||Failing a task is designed for signalling an error,
and should not be used to drive regular (non
exceptional) control flow.

To alter control flow, a better solution is using
conditions on precedence contraints instead.

You can set some variable in the script task, then
add on-success or on-completed precedence constraint
with condition that checks that variable.

Hope this helps,
Michael [SSIS Technical Lead]|||There are better ways to stop the task without returning failure result from the script task. For example, you could have an expression on the precedence constraint that checks a variable value you set in the script for whether to go on or not.
Try that, it will solve both problems I think.
K|||I have tried setting expressions within precedence constraint and it works. But I find setting variable and changing variable's value little kludge and I am surprised that Script Task does not have a property that will fail precedence constraint without raising an error.

On the contrary end, I guess it makes sense to have script task raise an error if I set it to failure manually, since all the other tasks have similiar behaviour. That is if they fail they raise OnError event.

Thanks everyone.|||

Do you want to force a failure result without actually throwing an error? If so try the ForceExecutionResult property. It is a container property, so available on all tasks.

|||

Hi

I think ive got a similar problem.

We have set up an SSIS package which goes to an FTP site and downloads files.

Everything is fine... EXCEPT (lol) when there are no files to download. This then fails the task.

However, I want the package to continue to run.

Is there away of assigning the error message given to an expression and then using the expression in the precedence contraint?

thanking you in advance

David

Script task

Hi,

I am new in SSIS development. In the script task of the Control Flow, how to use my custom classes (that use SMO and DTS for building a package and are written in C##?). If not the Script Task then which tool I have to use?

Natali Rozin wrote:

Hi,

I am new in SSIS development. In the script task of the Control Flow, how to use my custom classes (that use SMO and DTS for building a package and are written in C##?). If not the Script Task then which tool I have to use?

If you have compiled them into assemblies then you can reference them.

You should read this though:

VSA requires DLLs to be in the Microsoft.Net folder (but not all the time)
(http://blogs.conchango.com/jamiethomson/archive/2005/11/02/2341.aspx)

-Jamie

|||

thank you very much Jamie.

Did you put your DDLs into the root of the Microsoft.Net folder? Through "Add Reference", I cannot find my DDLs I just put into C:\WINDOWS\Microsoft.NET\Framework

|||

Natali Rozin wrote:

thank you very much Jamie.

Did you put your DDLs into the root of the Microsoft.Net folder? Through "Add Reference", I cannot find my DDLs I just put into C:\WINDOWS\Microsoft.NET\Framework

Natali,

You should put it into the appropriate .Net Framework version folder (I always just pick the highest). e.g.:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

My apologies, the post I linked to above does not explain this does it?

-Jamie

|||

Thank you - all are working!

The problem was I put mine into C:\WINDOWS\Microsoft.NET\Framework\v3.0 and do not have VS SDK yet.

In C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 works well!

thanks again

Tuesday, February 21, 2012

Scope_Identity and SqlDataSource

have a detailsView control with an SqlDataSource whose insert statement looks like this:

InsertCommand

="INSERT INTO [tblCompaniesNewSetRaw] ([NAME], [CITY], [ST], [ZIPCODE], [NAICS], [NAICSDESCRIPTION]) VALUES (@.NAME, @.CITY, @.ST, @.ZIPCODE, @.NAICS, @.NAICSDESCRIPTION); SELECT RETURN_VALUE = SCOPE_IDENTITY()"

also played with the same insert but used ...;Select SCOPE_IDENTITY()

my question is how do i get the last record inserted into tblCompaniesNewSetRaw after the insert is run. ie I read that the Select Scope_identity() would return the value but how do i access the return value from within the code behind page, iusing VB.

some things i tried in the detailsView_ItemInserted(...

Dim

rowAs DetailsViewRowForEach rowIn DetailsView3.Rows

x = row.Cells.Item(0).Text

Next

in the VS debugger x is just "" and not the last record inserted in that table.

probably way off base on this, clues appreciated, tc

I have never done it but i think what you will want to do is add a

InsertCommand="INSERT INTO [tblCompaniesNewSetRaw] ([NAME], [CITY], [ST], [ZIPCODE], [NAICS], [NAICSDESCRIPTION]) VALUES (@.NAME, @.CITY, @.ST, @.ZIPCODE, @.NAICS, @.NAICSDESCRIPTION); SELECT @.RETURN_VALUE = SCOPE_IDENTITY()"

<

asp:ParameterDirection="ReturnValue"Name="RETURN_VALUE"Type="Int16"/>

And then in the

ProtectedSub SqlDataSource1_Inserted(ByVal senderAsObject,ByVal eAs System.Web.UI.WebControls.SqlDataSourceStatusEventArgs)Handles SqlDataSource1.InsertedDim newIdAsObject = e.Command.Parameters("@.ReturnValue").ValueEndSub|||

sorry this

Dim newIdAsObject = e.Command.Parameters("@.ReturnValue").Value

should be this

Dim newIdAsObject = e.Command.Parameters("@.Return_Value").Value

|||

thanks rojay12

u gave me the clue i needed,

ended up using

Dim newIdAsObject = e.Command.Parameters("@.RETURN_VALUE").Value

<asp:ParameterName="RETURN_VALUE"Direction="Output"Type="Int32"/>

InsertCommand

="INSERT INTO [tblCompaniesNewSetRaw] ([NAME], [CITY], [ST], [ZIPCODE], [NAICS], [NAICSDESCRIPTION]) VALUES (@.NAME, @.CITY, @.ST, @.ZIPCODE, @.NAICS, @.NAICSDESCRIPTION); SELECT @.RETURN_VALUE = SCOPE_IDENTITY()

seems to be working, now got to go back and sync up some gridviews and the detailview afte the insert, much obliged, tc