Showing posts with label objects. Show all posts
Showing posts with label objects. Show all posts

Thursday, March 8, 2012

"Refresh" an SQLDataSource object programmatically

Background - I have a page that uses a numeric value stored in a Session object variable as the parameter for three different SQLDataSource objects, which provide data to two asp:Repeaters and an asp:DataList. Also, in the Page_Load, I use this value to to seed a stored procedure and an SQLDataReader to populate several unbound Labels. This works fine. In addition, I have a collection of 6 TextBoxes, an unbound Listbox, and two Buttons to allow the user to do searching and selection of potential matches. This basically identifies a new numeric value that I store in the Session variable and PostBack the page (via one of the buttons). This also works fine.

Problem - I have been tasked with taking a different page and adding six textboxes to collect the search values, but to post over to this page, populate the existing search-oriented TextBoxes, adn programmatically triggering the search. Furthermore, I have to detect the number of matching records and, if only 1, have the Repeaters and DataList display the results based on the newly selected record's key numeric value, as well as populating the unbound Labels. I have managed to get all of this accomplished except for programmatically triggering the Repeaters and DataList "refresh". These controls only populate as expected if a button is clicked a subsequent time, which makes sense, since that would trigger a PostBack and the Page_Load uses the new saved numeric key value from the Session.

My history in app development is largely from Windows Forms development (VB6), this is my second foray into Web Form dev with ASP.NET 2.0. I am willing to acceptthat what I am trying to do does not fit into the ASP environment, but I have to think that this is something that has been done before, and (hopefully) there is a way to do what I need.

Any ideas, oh great and wise Forum readers? *smile*

I don't think I have fully understood your problem. But when the user clicks search button you need to refresh the sqldatasource and call your_repeaters_or_datalist.DataBind() to refresh repeaters or datalist. If you have code in Post_Back you don't want to trigger you can include it in
if (!Page.IsPostBack)
{
////your code
}

|||

Thanks for the response. Hopefully this helps clarify my situation: The source page has several text boxes that mirror those on the target page. When a specific button on the source page is clicked, the contents of the source text boxes is written to the Session object and a redirect cross-posts to the target page. The Page_Load on the target page checks IsPostback and if it is a cross-page post, the code checks the origin of the action (via a Session variable), and updates the textboxes on the target page with the search parameters. In code, I poppulate a listbox (with results of a SQL stored procedure) with potential matches. If more than one match is returned, I want it to stop and await user interaction (And I have it at that point.) However, if only one match is returned, I have tried to save the key record value back to the Session object, so it can be available to the SQLDataSources that use it as its source value. This is not occurring.

IIn your response, you mentioned "you need to refresh the sqldatasource and call your_repeaters_or_datalist.DataBind() to refresh". That (refreshing the sqldatasource) is what I am trying to do. How can I get them to refresh without issuing an additional postback to the target page? Is there a method that I need to invoke on the sqldatasource objects to do that? It sounds like I am close, but not quite sure what to do at this point.

|||

Is there a method that I need to invoke on the sqldatasource objects to do that?

yes. Assume DataList control yourdatalist is bound to sqldatasource camDS,call following code to refresh:

camDS.SelectCommand ="searchcam";
camDS.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
camDS.SelectParameters.Add("keyword1","para1 ");
yourdatalist.DataBind();

How can I get them to refresh without issuing an additional postback to the target page?

I don't think this can be achieved without post back since data is saved at the server.

Friday, February 24, 2012

"Invalid Object.." error when using Copy SQL Server Objects task

SQL Server 2000. I have a production database, of which, I want to
make a copy. I created a DTS with the Copy SQL Server Obj Task to copy
all objects from MyDbName to MyDbName_Test (on the same instance of SQL
Server). I've used this method on other databases many times and it
completes just fine. On this db, however, I get "Invalid object name
'dbo.vwWhereUsed'" when trying to complete the task. vwWhereUsed is, of
course, one of my views. This view functions properly when ran. I
later found that the error seemed to be happening when the DTS attempts
to copy another view that calls vwWhereUsed. This other view does not
get copied to MyDbName_Test before the DTS fails, but vwWhereUsed is
copied.
My thought was that the other view is being copied to the new db before
vwWhereUsed and blowing up because vwWhereUsed is not there yet... but
from what I just explained, that doesn't seem to be the case.
On another DTS attempt to move a few tables,that have nothing to do
with vwWhereUsed, into a new clean database (MyDBName_Test) I got the
same error message (Invalid object name 'dbo.vwWhereUsed').
Interestingly enough, if I UNcheck the "Drop Destination Objects First"
option before moving those tables, the error does not occur. This does
not make sense, because it was a NEW db.. there was nothing to DROP.
Is there something I'm not seeing here? or..
Is there techniques to help me discover exactly whats happening.. or
any tips on making copies of databases using the Copy SQL Server Object
Task that may help correct this issue?
TIALindsey,
Seems like a lot of unnecessary work. Why not use a BACKUP/RESTORE
approach? Or if the DB can be offline (say afterhours)
sp_detach_db/sp_attach_db?
HTH
Jerry
"lindseyhansen" <lindsey.hansen@.fmc-na.com> wrote in message
news:1128614409.695658.177570@.o13g2000cwo.googlegroups.com...
> SQL Server 2000. I have a production database, of which, I want to
> make a copy. I created a DTS with the Copy SQL Server Obj Task to copy
> all objects from MyDbName to MyDbName_Test (on the same instance of SQL
> Server). I've used this method on other databases many times and it
> completes just fine. On this db, however, I get "Invalid object name
> 'dbo.vwWhereUsed'" when trying to complete the task. vwWhereUsed is, of
> course, one of my views. This view functions properly when ran. I
> later found that the error seemed to be happening when the DTS attempts
> to copy another view that calls vwWhereUsed. This other view does not
> get copied to MyDbName_Test before the DTS fails, but vwWhereUsed is
> copied.
> My thought was that the other view is being copied to the new db before
> vwWhereUsed and blowing up because vwWhereUsed is not there yet... but
> from what I just explained, that doesn't seem to be the case.
> On another DTS attempt to move a few tables,that have nothing to do
> with vwWhereUsed, into a new clean database (MyDBName_Test) I got the
> same error message (Invalid object name 'dbo.vwWhereUsed').
> Interestingly enough, if I UNcheck the "Drop Destination Objects First"
> option before moving those tables, the error does not occur. This does
> not make sense, because it was a NEW db.. there was nothing to DROP.
>
> Is there something I'm not seeing here? or..
> Is there techniques to help me discover exactly whats happening.. or
> any tips on making copies of databases using the Copy SQL Server Object
> Task that may help correct this issue?
> TIA
>|||Thanks Jerry.. I haven't tried that before.. I'll give it a shot. It
still makes me nervous, however, that I can't get the dts to complete
successfully. I've run the dbcc check on the database and everything
is fine. I'm not sure what else to look at.
Thanks, though.

"Invalid Object.." error when using Copy SQL Server Objects task

SQL Server 2000. I have a production database, of which, I want to
make a copy. I created a DTS with the Copy SQL Server Obj Task to copy
all objects from MyDbName to MyDbName_Test (on the same instance of SQL
Server). I've used this method on other databases many times and it
completes just fine. On this db, however, I get "Invalid object name
'dbo.vwWhereUsed'" when trying to complete the task. vwWhereUsed is, of
course, one of my views. This view functions properly when ran. I
later found that the error seemed to be happening when the DTS attempts
to copy another view that calls vwWhereUsed. This other view does not
get copied to MyDbName_Test before the DTS fails, but vwWhereUsed is
copied.
My thought was that the other view is being copied to the new db before
vwWhereUsed and blowing up because vwWhereUsed is not there yet... but
from what I just explained, that doesn't seem to be the case.
On another DTS attempt to move a few tables,that have nothing to do
with vwWhereUsed, into a new clean database (MyDBName_Test) I got the
same error message (Invalid object name 'dbo.vwWhereUsed').
Interestingly enough, if I UNcheck the "Drop Destination Objects First"
option before moving those tables, the error does not occur. This does
not make sense, because it was a NEW db.. there was nothing to DROP.
Is there something I'm not seeing here? or..
Is there techniques to help me discover exactly whats happening.. or
any tips on making copies of databases using the Copy SQL Server Object
Task that may help correct this issue?
TIA
Lindsey,
Seems like a lot of unnecessary work. Why not use a BACKUP/RESTORE
approach? Or if the DB can be offline (say afterhours)
sp_detach_db/sp_attach_db?
HTH
Jerry
"lindseyhansen" <lindsey.hansen@.fmc-na.com> wrote in message
news:1128614409.695658.177570@.o13g2000cwo.googlegr oups.com...
> SQL Server 2000. I have a production database, of which, I want to
> make a copy. I created a DTS with the Copy SQL Server Obj Task to copy
> all objects from MyDbName to MyDbName_Test (on the same instance of SQL
> Server). I've used this method on other databases many times and it
> completes just fine. On this db, however, I get "Invalid object name
> 'dbo.vwWhereUsed'" when trying to complete the task. vwWhereUsed is, of
> course, one of my views. This view functions properly when ran. I
> later found that the error seemed to be happening when the DTS attempts
> to copy another view that calls vwWhereUsed. This other view does not
> get copied to MyDbName_Test before the DTS fails, but vwWhereUsed is
> copied.
> My thought was that the other view is being copied to the new db before
> vwWhereUsed and blowing up because vwWhereUsed is not there yet... but
> from what I just explained, that doesn't seem to be the case.
> On another DTS attempt to move a few tables,that have nothing to do
> with vwWhereUsed, into a new clean database (MyDBName_Test) I got the
> same error message (Invalid object name 'dbo.vwWhereUsed').
> Interestingly enough, if I UNcheck the "Drop Destination Objects First"
> option before moving those tables, the error does not occur. This does
> not make sense, because it was a NEW db.. there was nothing to DROP.
>
> Is there something I'm not seeing here? or..
> Is there techniques to help me discover exactly whats happening.. or
> any tips on making copies of databases using the Copy SQL Server Object
> Task that may help correct this issue?
> TIA
>
|||Thanks Jerry.. I haven't tried that before.. I'll give it a shot. It
still makes me nervous, however, that I can't get the dts to complete
successfully. I've run the dbcc check on the database and everything
is fine. I'm not sure what else to look at.
Thanks, though.

"Invalid Object.." error when using Copy SQL Server Objects task

SQL Server 2000. I have a production database, of which, I want to
make a copy. I created a DTS with the Copy SQL Server Obj Task to copy
all objects from MyDbName to MyDbName_Test (on the same instance of SQL
Server). I've used this method on other databases many times and it
completes just fine. On this db, however, I get "Invalid object name
'dbo.vwWhereUsed'" when trying to complete the task. vwWhereUsed is, of
course, one of my views. This view functions properly when ran. I
later found that the error seemed to be happening when the DTS attempts
to copy another view that calls vwWhereUsed. This other view does not
get copied to MyDbName_Test before the DTS fails, but vwWhereUsed is
copied.
My thought was that the other view is being copied to the new db before
vwWhereUsed and blowing up because vwWhereUsed is not there yet... but
from what I just explained, that doesn't seem to be the case.
On another DTS attempt to move a few tables,that have nothing to do
with vwWhereUsed, into a new clean database (MyDBName_Test) I got the
same error message (Invalid object name 'dbo.vwWhereUsed').
Interestingly enough, if I UNcheck the "Drop Destination Objects First"
option before moving those tables, the error does not occur. This does
not make sense, because it was a NEW db.. there was nothing to DROP.
Is there something I'm not seeing here? or..
Is there techniques to help me discover exactly whats happening.. or
any tips on making copies of databases using the Copy SQL Server Object
Task that may help correct this issue?
TIALindsey,
Seems like a lot of unnecessary work. Why not use a BACKUP/RESTORE
approach? Or if the DB can be offline (say afterhours)
sp_detach_db/sp_attach_db?
HTH
Jerry
"lindseyhansen" <lindsey.hansen@.fmc-na.com> wrote in message
news:1128614409.695658.177570@.o13g2000cwo.googlegroups.com...
> SQL Server 2000. I have a production database, of which, I want to
> make a copy. I created a DTS with the Copy SQL Server Obj Task to copy
> all objects from MyDbName to MyDbName_Test (on the same instance of SQL
> Server). I've used this method on other databases many times and it
> completes just fine. On this db, however, I get "Invalid object name
> 'dbo.vwWhereUsed'" when trying to complete the task. vwWhereUsed is, of
> course, one of my views. This view functions properly when ran. I
> later found that the error seemed to be happening when the DTS attempts
> to copy another view that calls vwWhereUsed. This other view does not
> get copied to MyDbName_Test before the DTS fails, but vwWhereUsed is
> copied.
> My thought was that the other view is being copied to the new db before
> vwWhereUsed and blowing up because vwWhereUsed is not there yet... but
> from what I just explained, that doesn't seem to be the case.
> On another DTS attempt to move a few tables,that have nothing to do
> with vwWhereUsed, into a new clean database (MyDBName_Test) I got the
> same error message (Invalid object name 'dbo.vwWhereUsed').
> Interestingly enough, if I UNcheck the "Drop Destination Objects First"
> option before moving those tables, the error does not occur. This does
> not make sense, because it was a NEW db.. there was nothing to DROP.
>
> Is there something I'm not seeing here? or..
> Is there techniques to help me discover exactly whats happening.. or
> any tips on making copies of databases using the Copy SQL Server Object
> Task that may help correct this issue?
> TIA
>|||Thanks Jerry.. I haven't tried that before.. I'll give it a shot. It
still makes me nervous, however, that I can't get the dts to complete
successfully. I've run the dbcc check on the database and everything
is fine. I'm not sure what else to look at.
Thanks, though.

Friday, January 27, 2012

HELP ! Disappearing objects

We are supposed to be deploying to SQL2K5 this friday night. I've been
taking backups from our SQL 2K server and restoring them directly on our 2K5
box. Everything seems to work ok except for one of our databases. When I
expand the "views" in Sql Management Studio object browser I get an error
that says "Parameter cannot be null" and none of the objects are there!!!
All other object types seem fine and only this database exhibits this
behavior. I'm not sure how to track this down.the error message is actually this
Value cannot be null.
Parameter name: context (ObjectExplorer)
"Tim Greenwood" <tim_greenwood A-T yahoo D-O-T com> wrote in message
news:%23QwU%23MMaGHA.4788@.TK2MSFTNGP02.phx.gbl...
> We are supposed to be deploying to SQL2K5 this friday night. I've been
> taking backups from our SQL 2K server and restoring them directly on our
> 2K5 box. Everything seems to work ok except for one of our databases.
> When I expand the "views" in Sql Management Studio object browser I get an
> error that says "Parameter cannot be null" and none of the objects are
> there!!! All other object types seem fine and only this database exhibits
> this behavior. I'm not sure how to track this down.
>|||One thing that I know doesn't work in 2005 is databases in a too low compatibility mode (60 and 65,
I believe). I'd think that SSMS would give a better error message, but worth looking into.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Tim Greenwood" <tim_greenwood A-T yahoo D-O-T com> wrote in message
news:%23dtxLQMaGHA.3304@.TK2MSFTNGP04.phx.gbl...
> the error message is actually this
> Value cannot be null.
> Parameter name: context (ObjectExplorer)
> "Tim Greenwood" <tim_greenwood A-T yahoo D-O-T com> wrote in message
> news:%23QwU%23MMaGHA.4788@.TK2MSFTNGP02.phx.gbl...
>> We are supposed to be deploying to SQL2K5 this friday night. I've been taking backups from our
>> SQL 2K server and restoring them directly on our 2K5 box. Everything seems to work ok except for
>> one of our databases. When I expand the "views" in Sql Management Studio object browser I get an
>> error that says "Parameter cannot be null" and none of the objects are there!!! All other object
>> types seem fine and only this database exhibits this behavior. I'm not sure how to track this
>> down.
>|||And what if you query sys.objects? Are the object listed in
the catalog view? Or in the information_schema.views view?
I've hit a few flaky things like that with SSMS. Usually
when I hit the bug with the index error in SSMS, I start
seeing other object display issues until I close SSMS and
reopen. I think some, most of those are fixed in SP1 for SQL
2005.
-Sue
On Tue, 25 Apr 2006 16:51:57 -0700, "Tim Greenwood"
<tim_greenwood A-T yahoo D-O-T com> wrote:
>We are supposed to be deploying to SQL2K5 this friday night. I've been
>taking backups from our SQL 2K server and restoring them directly on our 2K5
>box. Everything seems to work ok except for one of our databases. When I
>expand the "views" in Sql Management Studio object browser I get an error
>that says "Parameter cannot be null" and none of the objects are there!!!
>All other object types seem fine and only this database exhibits this
>behavior. I'm not sure how to track this down.
>