DataSource Controls :: SqlDataSource Query Not Using Index On Database Table?
Jan 20, 2011
I have this sqldatasource:
<asp:sqldatasource id="SqlDataSourceX" runat="server" connectionstring="<%$ ConnectionStrings:MyConn%>" providername="System.Data.SqlClient"
selectcommand="SELECT ItemNum, MIN(DateAdded) as [DateAdded]
FROM Items WITH (NOLOCK)
WHERE [DateAdded] between @DateFrom AND @DateTo
[Code]....
When I call select in codebehind, after 30sec it throws timeout expired SqlException:
[Code]....
again , this select took up to 3 sec to be executed. In application I tried to use SqlConnection and SqlTableAdapter instead of SqlDataSource, with the same query, and again it took up to 3 sec.
If I choose tighter interval (e.g '2011-01-20 00:00:00' - '2011-01-21 00:00:00') , there is no timeout exception, so I know that sqldatasource select is executed correctly. So the conclusion is that sql server is not using index while executing query sent from sqldatasource, but is using index whenever else. I have also checked the index statistics on sql server and it is like that. In profiler i can see slight difference between this two cases. As for SqlDataSource, in events table, in first column "EventClass" after 30 sec, there is this: "RPC:Completed" and application throws timeout. If i use SqlConnection and SqlTableAdapter then at the same place there is this: "SQL:BatchStarting" and "SQL:BatchCompleted" and application does not throws timeout(the index has been used).
what is so special on SqlDataSource connection, that Sql Server performs differently compared to other types of connections?
1. I have a GridView on my page and it uses sqldatasource with parameterized query. What I want to do is, on page load (where nothing has been selected so no parameter supplied), I want it to query everything (something like SELECT * FROM [this_table]) but since my SelectCommand is something like
SELECT * FROM [this_table] WHERE [this_column] = @someParameters AND [that_column] = @someParameters.
Can I play around with default value to achieve something like that but how ? Now, when the page loads, it doesn't show anything (No Gridview).
2. On my page, I made something like (username, gender, address, and more) and one single search button. That means, no single control enable auto postback. What I am trying to accomplish is building dynamic query
(if username specifed -> SELECT * FROM [this_table] WHERE [username] LIKE @username).
If both username and gender are specified (SELECT * FROM [this_table] WHERE [username] LIKE @username AND [gender] = @gender) and you know the rest. How can I do this using GridView and SqlDataSource ? To my knowledge, I can only specify one SELECT statement in a sqldatasource.
I'm implementing a BLL layer and have a few questions. First, in my DAL, there is a contacts table, the select method is a sql query against a sql server 2000 database. The preview data returns everyting as expected. The query is
[Code]....
The BLL method is built like so
[Code]....
When using the BLL method to a gridview, the results of the subquery are not displayed. There are also other methods, each having a different where clause for ContactRole_ID and each is having the same issue of not displaying the subquery reult in the gridview. No error, but no data is displayed for the subquery either. Here is the templatefield of the gridview
[Code]....
Another item that is causing an error is in trying to update a record. Here is the DAL update method
[Code]....
And the BLL update method
[Code]....
The error says i have extra parameters, but have no clue where the extra parameters are being picked up. The error isObjectDataSource 'odsContacts' could not find a non-generic method 'UpdateContact' that has parameters: _ContactID, _Active, _ContactName, _Office, _VirtualOffice, _Pager, _Fax, _Home, _Cellular, _Email, _ContactRole_ID, Active, ContactRole_ID, ContactName, Office, Email, VirtualOffice, Pager, FAX, Home, Cellular.And the objectdatasource
I have an editable grid where user can add/edit data. They also have the option to load previously entered data from last month. When the user then clicks save, i want to readd this newly modified data as a new record for this month. So basically I want to call the insertcommand, but it does not work. My 'save' method just 'updates' the records.
Providing sqldatasource, grid and save method <asp:SqlDataSource ID="SqlDataSourceLoadActivities" runat="server" [code].....
I have a strange problem...I am programatically adding an SQL SELECT query to my SqlDataSource that my GridView is bound to. If I use the follwing statement it works fine:
[Code]....
But if I use the following one, the gridview fails to load. The only way that this is different is it uses RTRIM and CAST on one of the fields:
[Code]....
I don't understand why this can be. If I try the statement exactly how it is in the query builder and run it it returns the rows no problem.
I have a gridview which I connect by C# and SqldataSource. I use asp.net 2.0 - 3.5.
I want to parameterized the queries and how do I do this in the C# file ? how do I set the selectparameters in C# ?. I do not want to do this in the aspx fil.
My code in C# is:
SqlDataSourceMachineName.SelectParameters.Clear(); SqlDataSourceMachineName.SelectCommand = "Select MachineName from tblMachine inner join tblLocation on tblMachine.MachineLocationID = tblLocation.LocationID where tblLocation.LocationName = 'New York' and tblMachine.StatusID = '1'";
Currently, I have long script which does major processing and then puts data into temp table.
Finally I read data from this temp table to show on the chart, based on user's selection of parameter. So I can divide my query into two parts and while I am researching this,
Is it possible to do processing in one Datasource and read table from second datasource?Is it even possible?
If not, what is recommended method for this (breaking large processing into small one)?
I have a query that I want to test the performance of when the query is included directly in the SqlDataSource versus when I call a stored procedure. Does anyone have suggestions on how I would be able to closely watch the actual steps here? I was thinking of turning on tracing and adding Trace.Write for each of the events that fire along the way. This doesn't seem efficient and I wanted to see if there was a better approach.
I single table in SQL Server having 50 columns col_1 to col_50 having type varchar(MAX)..The table is having nearly 2 crore data into it which is unstructured i.e. just put in by bulk copy. I have to perform search operation on this table. How to index the table so as to make the search fast? or any other way to make the search fast.
I know this sounds odd. I have a SQL DB that I am pulling data from. I have to some math functions to get a percentage. So I am pulling all the data in my code and building a data table with the results. I am then trying to pass this into a chart control that I have, but it fails because the data source is not correct for the chart control. I know that the chart control will accept a SQLDataSource control as a data source because a built a example with it before using it in my project.So my question is how can I use the Data Table as a data source for a SQLDataSource Control? Or is there a way I can pull the data from my DB andapply the math needed in a stored procedure or something similar that I could create the procedure on my SQL server then add a SQLDataSource control to my page and use the stored procedure as the source for the SQLDataSource Control.
By right clicking on my database i created a query in server explorer. But where are this query stored can't find them back. I should aspect that their is a folder query's like there is a folder tables but this isn't the case.
i am using a gridview which shows the data and a select column. when the user selects a record a detailsview is shown with the respective details and an edit button inside it. when the user clicks on the edit button the entire detailsview becomes editable and the user can now edit the selected record .here the problem starts cause when the user clicks on the update button there is an error stating that illegal variable/number or parameter not found.i am using sqldatasource to bind the gridview and detailsview with an unique RequestId fieldwhich detailsview sql datasource uses to bind the record uniquely.
I have a mssql table of names. This table contains names from A thru Z. However, I want to be able to display names by their beginning alphabet...Like first Display names A thru CThen Display Names D thru F and ..so on....and so forth....thru ZI using asp.net and have a grid view with paging enabled.....
What ive been using now is getting datas in code-behind, passing datasource into a Session, re-binds it to a gridview whenever there's paging/sorting needed. What i want to know is what is better if its performance we are talking about?
Is it datasource into a session Or SqlDataSource for which I know whenever paging/sorting needed is that sqldatasource opens up a DB connection to get the datas again?
everytime I modify an SQLdatasource using VS wizards, I have to dettach the mdf in VS's server exporer, then hit refresh in the browser, then get the applicaiton is offline error message please remove some pia file, but i usually just count to 12 and then hit refresh again and the page renders properlyhad scoured the forum on more than one ocasstiion, think it has something to do with the Admin rights within SQL, Ive tried the SQL server surface configuration tool, and add administrator stuff, but not sure if i should add (user to provision) something like the asp.net thing, or network services or ??also cant figure out where to view which administrators are actually on SQL server,
I have this working on another project I have but cannot figure out why I can't get it to work on another. I have a dropdownlist box with employee names. When an employee is selected, I display the data (address, phone, email, etc.) in a series of textboxes. User can make changes and then click on an "Update" button where I attempt to update the database with the changes using the sqldatasource. The code works without any errors, but the database does not update.
Here's the sqldatasource code (the code behind follows):
[Code]....
Code Behind for the "Update" button control which was intended to update the database with sqldatasource3.update() command at the end:
ItemNo refno Process Name Qty 001 1 A John 50 001 2 A Jon 150 002 3 B Kalis 100 003 4 A Bob 300 Second Table ItemNo Newrefno Process Name Qty 001 001 ZZ peter 50 001 001/a ZkZ Joe 70 002 002 Ab Ray 100 Result Set 001 A John 200 001/a ZZ ZkZ peter joe 50 70 002 B Kalis 100 002 Ab Null Ray Null 100 Null 003 A Bob 300 null null null null null null null
Here first row of the result set explanation:
up to this 001 A John 200 based on first table sum...
and 001/a zz ZkZ peter joe 50 70
here 001/a newrefno of 001 so i need to show all the ItemNo 001 record in one row like the above resultset.
I have a button click event that adds a record to a table based on the userid and threadid the user is viewing. I am a bit new to entity so I am stumbling around. I have to where conditions
ThreadID == threadid UserId == userIdPosts
I have this query but do not know how to execute it and if I have it as is I get this in the yellow screen of death Both the theadid and userIdPosts have data in them.
Line 90: // find is user has already tracked this thread. Line 91: var query = context.TrackLists.First(t => t.ThreadID == threadid); Line 92: context.TrackLists.First(t => t.UserId == userIdPosts);
I have a table in my aspnet database. I added a bottom row "Not Selected", if the user doesn't select from a databound drop down list. This row is at the bottom, because I just added it to the table data. Is there any way to move this one row to the top of the table manually? There is not "cut" and "paste" when I select the whole row.
I am trying to update my table ARTICLES and it has a field COUNTER, Everytime a user enter this ARTICLES, the page_load event runs a LINQ to SQL query taking the QueryString as parameter, increasing the COUNTER field in 1.