Showing posts with label dynamically. Show all posts
Showing posts with label dynamically. Show all posts

Friday, March 23, 2012

How do I identify the replication generated column(s) in a table

I need to dynamically generate a select command that does not include
replication generated columns. Is there a way to do this? I could use
GetOleDbSchemaTable and filter for column names with "rowguid" but that does
not seem robust to me. Is there a system table or stored procedure that can
help? Dropping a replication subscription and publication removes these
columns so I suspect that the information is available somewhere.
Thanks
Dropping a publication doesn't drop the guid columns added to a merge
publication. As far as I know we can't identify those columns added.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com .
|||What about something like this:
declare @.mystring varchar(2000)
set @.mystring='select '
select @.mystring=@.mystring+' '+name+', ' From syscolumns where
id=object_id('customers')
and name <>'rowguid'
select @.mystring=substring(@.mystring,1,len(@.mystring)-1)+' from customers'
print @.mystring
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Kohn" <Kohn@.discussions.microsoft.com> wrote in message
news:915755D4-E2FC-4790-B0E8-6E493DE1BA4F@.microsoft.com...
>I need to dynamically generate a select command that does not include
> replication generated columns. Is there a way to do this? I could use
> GetOleDbSchemaTable and filter for column names with "rowguid" but that
> does
> not seem robust to me. Is there a system table or stored procedure that
> can
> help? Dropping a replication subscription and publication removes these
> columns so I suspect that the information is available somewhere.
> Thanks
>
|||Hi Hilary - unfortunately this doesn't work . We could query for the
rowguid column on the table, but that might already have existed prior to
the replication setup. As far as I can tell there isn't a way of knowing if
the rowguid column is added by the replication setup or by a user
beforehand.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com .
|||It will work for the majority of the cases.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
news:O$uP0uJNHHA.3424@.TK2MSFTNGP02.phx.gbl...
> Hi Hilary - unfortunately this doesn't work . We could query for the
> rowguid column on the table, but that might already have existed prior to
> the replication setup. As far as I can tell there isn't a way of knowing
> if the rowguid column is added by the replication setup or by a user
> beforehand.
> Cheers,
> Paul Ibison SQL Server MVP, www.replicationanswers.com .
>
|||Another thing to take into account is that replication does not require
the column to be called rowguid. It just requires a column with the
ROWGUIDCOL property set. Maybe that is where you should start looking.
Hilary Cotter wrote:
> What about something like this:
> declare @.mystring varchar(2000)
> set @.mystring='select '
> select @.mystring=@.mystring+' '+name+', ' From syscolumns where
> id=object_id('customers')
> and name <>'rowguid'
> select @.mystring=substring(@.mystring,1,len(@.mystring)-1)+' from customers'
> print @.mystring
>
|||I had a quick look and it seems you have to look for colomns where
syscolumns.colstat = 2. You can also only have one column per table with
the ROWGUIDCOL property set, so you can be pretty sure that is the
column used by replication. So to modify Hilary's query:
declare @.mystring varchar(2000)
set @.mystring='select '
select @.mystring=@.mystring+' '+name+', ' From syscolumns where
id=object_id('customers')
and colstat <> 2
select @.mystring=substring(@.mystring,1,len(@.mystring)-1)+' from
customers'
print @.mystring
JE wrote:[vbcol=seagreen]
> Another thing to take into account is that replication does not require
> the column to be called rowguid. It just requires a column with the
> ROWGUIDCOL property set. Maybe that is where you should start looking.
>
> Hilary Cotter wrote:
|||The information for identifying the column with the rowguid property solves
the problem. My app retrieves the information with the GetOleDbSchemaTable
function (see below).
By the way, rowguid columns created by the wizard are removed when dropping
the publication. I suspect it uses the preserve_rowguidcol column in the
sysmergearticles tables.
cn.Open()
Dim t As DataTable = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns,
New Object() {Nothing, Nothing, TableName, Nothing})
cn.Close()
cn.Dispose()
Dim SelectRows() As DataRow
SelectRows = t.Select("(DATA_TYPE <> 72) AND
(COLUMN_HASDEFAULT=FALSE) AND (COLUMN_HASDEFAULT=False) AND
((ISNULL(COLUMN_DEFAULT,'T')='T') OR
(COLUMN_DEFAULT<>'(newsequentialid())'))")
Dim SelectListStringBuilder As New System.Text.StringBuilder
For Each r As DataRow In SelectRows
SelectListStringBuilder.Append(r.Item("COLUMN_NAME "))
SelectListStringBuilder.Append(",")
Next
SelectListStringBuilder.Length -= 1
Debug.WriteLine(SelectListStringBuilder.ToString)
Thanks for the help

Friday, February 24, 2012

How do i Edit the Package Source file name Dynamically

Hi

I have created a package using DTS Designer to import the data from flat file to the SQL server.
i have sheduled the package to execute at every 1st day of the month and saved the the package to the local server.

i want to do the following steps dynamically from the Visual Basic

1. i am loading all the packages from the local server and also from the metadata services into a combo box. select one package from the combo box and i want to change the package shedule time from vb and i want to save the package back to the sql server.

2. when the package is executing at the schedule time at that time i want to change the source of the package that means flat filename(to different filename) and i need to execute the package and save the package.

how do i do this dynamically.

Thanks in advance

Regards
GandhiThe package schedule time is really a job schedule time - so you would use the sp_update_jobschedule stored procedure. For the 2nd part, when would the filename change and what would change it ?

How do I dynamically set the MultiValue property for 1 parameter based on another?

I am trying to set the property of 1 parameter based on the results of another parameter.

For example:

Parameters: PA and PB

If the user selects All or multiple values for PA

Then PB should not be MultiValue

Otherwise PB should be MultiValue

Does anyone have any suggestions?

Thanks

You could make PB MulitValue always, but have it's dataset filtered based on the PA parameter values. You just have to make sure PA comes first in your parameters list.

Hope that helps.

How do I dynamically change the ReportViewer's focus from one RDLC to another at runtime in cod

Howdy friends,

I have a question regarding SQL Reporting Services 2005. I have raised this question in several other places, only to watch it go unanswered. Hope to recieve the answer here.

I am using a SQL Reporting Services .RDLCs inside a Visual Basic 2005 windows client application. This is not webclient or web context; it is a Windows client. We will run the reports on the client side, not server side. The reports are embedded resources deployed in an MSI along with the rest of the application. I have one WinForm in the project which hosts the ReportViewer control. We have 5 unique RDLC report definitions. Any of our end user may want or need to preview at any of these 5 reports inside this single ReportViewer WinForm at run time.

So far I have found absolutely no way to dynamically change the RDLC which the ReportViewer displays at run time, and in code. How can this be done?

Whenever I ask this question, some joker always pops and says "That's easy, you just open your form in Visual Studio and use the smart tags to go through the binding setup." That is not particularly helpful because it doesn't answer the question. The question is not how to redesign the form inside Visual Studio with smart tags. The question is how to dynamically change the report that the ReportViewer displays dynamically, at runtime, and in code.

At the moment I think there is no solution to this problem. It seems that an RDLC is bound to the ReportViewer at design time and is immutably fixed at runtime. So far I have seen no working code which changes ReportVIewer from one RDLC to another. I am close to reaching the conclusion that I must make 5 copies of the same form, and bind 1 copy to 1 .RDLC in design mode. This is a pretty lame-arse solution if you ask me.

Anybody have a clue?

I am also struggling with the same problem.

I tried changing the ReportPath to a different rdlc at runtime. I also added a new "objectdatasource" to the Viewer window. However, I'm not sure how to specify which "objectdatasource" the ReportViewer should use.

Can Dave be right? "It seems that an RDLC is bound to the ReportViewer at design time and is immutably fixed at runtime. "

|||

When you bind the report viewer control to the form, there is a call to load the report on startup. You can remove this call, change the properties dynamically, then load the selected report in the viewer.

I bound Report1.rdlc to my viewer control.

I commented out the following line of code in the form load method.

//this.reportViewer1.RefreshReport();

And added:

this.reportViewer1.LocalReport.ReportEmbeddedResource = "WindowsApplication1.Report2.rdlc";

this.reportViewer1.RefreshReport();

The WindowsApplication1.Report2.rdlc could be a method that dynamically sets the value.

Check out http://www.gotreportviewer.com from more tips.

How do I dynamically change the ReportViewer's focus from one RDLC to another at runtime in

Howdy friends,

I have a question regarding SQL Reporting Services 2005. I have raised this question in several other places, only to watch it go unanswered. Hope to recieve the answer here.

I am using a SQL Reporting Services .RDLCs inside a Visual Basic 2005 windows client application. This is not webclient or web context; it is a Windows client. We will run the reports on the client side, not server side. The reports are embedded resources deployed in an MSI along with the rest of the application. I have one WinForm in the project which hosts the ReportViewer control. We have 5 unique RDLC report definitions. Any of our end user may want or need to preview at any of these 5 reports inside this single ReportViewer WinForm at run time.

So far I have found absolutely no way to dynamically change the RDLC which the ReportViewer displays at run time, and in code. How can this be done?

Whenever I ask this question, some joker always pops and says "That's easy, you just open your form in Visual Studio and use the smart tags to go through the binding setup." That is not particularly helpful because it doesn't answer the question. The question is not how to redesign the form inside Visual Studio with smart tags. The question is how to dynamically change the report that the ReportViewer displays dynamically, at runtime, and in code.

At the moment I think there is no solution to this problem. It seems that an RDLC is bound to the ReportViewer at design time and is immutably fixed at runtime. So far I have seen no working code which changes ReportVIewer from one RDLC to another. I am close to reaching the conclusion that I must make 5 copies of the same form, and bind 1 copy to 1 .RDLC in design mode. This is a pretty lame-arse solution if you ask me.

Anybody have a clue?

I am also struggling with the same problem.

I tried changing the ReportPath to a different rdlc at runtime. I also added a new "objectdatasource" to the Viewer window. However, I'm not sure how to specify which "objectdatasource" the ReportViewer should use.

Can Dave be right? "It seems that an RDLC is bound to the ReportViewer at design time and is immutably fixed at runtime. "

|||

When you bind the report viewer control to the form, there is a call to load the report on startup. You can remove this call, change the properties dynamically, then load the selected report in the viewer.

I bound Report1.rdlc to my viewer control.

I commented out the following line of code in the form load method.

//this.reportViewer1.RefreshReport();

And added:

this.reportViewer1.LocalReport.ReportEmbeddedResource = "WindowsApplication1.Report2.rdlc";

this.reportViewer1.RefreshReport();

The WindowsApplication1.Report2.rdlc could be a method that dynamically sets the value.

Check out http://www.gotreportviewer.com from more tips.

How do I dynamically change the "TOP X" portion of a SELECT

I'm sure I'm missing something. I am returning the TOP X number of customers by revenue and I'd like to change the number of records returned by passing a parameter but I keep getting an error.

@.TopX int ( or varchar)

SELECT @.TopX CompanyName, Amount FROM Sales Where....

Why will this not work?

Only works in SQL Server 2005 or SQL Express:

SELECT TOP (@.Topx) ...

|||

Only works in SQL Server 2005 or SQL Express:

SELECT TOP (@.Topx) ...

|||
DECLARE @.stmtvarchar(500)DECLARE @.top varchar(5)SET @.top ='10'SET @.stmt ='SELECT TOP ' + @.top +' * FROM [Products]'EXEC(@.stmt)
You can dynamically create a sql statement:|||

Upgraded to 2005 and that worked perfectly...

Thanks!