|
Hi
i created a web service to load some information from sql server 2005 database, it works good but it has very low speed to return data, wheras sql server load data without overhead. i think the decreasing performance occures in while loop, here is my code :
[WebMethod]
public List<InputOutput> GetAllInputOuts()
{
List<InputOutput> list = new List<InputOutput>();
using (System.Data.SqlClient.SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["IOXPConnectionString"].ConnectionString))
{
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "select * from vLinkToDataSource";
SqlDataReader dr = null;
if (con.State != ConnectionState.Open)
con.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
InputOutput io = new InputOutput();
io.Code = dr.GetInt32(2);
io.Name = dr.GetString(1);
io.Family = dr.GetString(0);
io.DateInput = dr.GetString(3);
io.TimeInput = dr.GetString(4);
io.DateOutput = dr.GetString(5);
io.TimeOutput = dr.GetString(6);
list.Add(io);
}
}
}
return list;
}
how to improve the performance ?
Note 1 : the sql server 2005 return results good.
Note 2 : almost 17000 records exists in database.
Note 3 : beacuse i want to use this web Service in sharepoint, i must return result as List<T>.
Any help would be great appreciated
|
|
|
|
|
So, you're returning all 17,000 records, adding them one at a time to the List<t>, then having the Web Method serialize the entire List<t> (will probably take a while), tranferring what amounts to megabytes of XML text, then having the client deserialize the entire list (will probably take a while, again)??
I think you biggest problem is trying to handle 17,000 records all at once. I'd probably want to limit the data I return from the database and reduce the dataset to only the data that is absolutely necessary at a certain point in time. What are you doing with all 17,000 records that you need to transfer them all?
|
|
|
|
|
Hi Dave
my goal is load all data into sharepoint via bussiness data catalog (bdc), it's finder method, then write another webMethod to find only data which matched to criteria, It's specific finder method.
|
|
|
|
|
Well, then I'd probably look at a caching solution on the Sharepoint side if your data doesn't change very often, or if your SQL Server is 2005 or above, some kind of solution to return the query as your XML dataset and returning that to the client.
|
|
|
|
|
Thanks Dave
but, what's XML dataset ?
can u give me an example ?
thanks
|
|
|
|
|
I don't have any examples, but you can start your own research into it by Googling for "SELECT FOR XML".
|
|
|
|
|
I am experiencing difficulty trying to make a trackbar scroll when the middle mouse button/ball is clicked and scrolled.
I need the mouse scroll wheel to scroll up and down when it is clicked and reset the value to the middle when realised.
Does anyone know how this can be done.
Thanx George
|
|
|
|
|
I have tried this:
private void trackBar1_Scroll_1(object sender, MouseEventArgs m)
{
if (m.Button == MouseButtons.Middle)
{
label1.Text = trackBar1.Value.ToString();
}
}
but dont know if it will work as havent got it to compile because its complaining about the delegate
this.trackBar1.Scroll += new System.EventHandler(this.trackBar1_Scroll_1);
I dont know how to change it, it works with eventArgs but i put in mouseEventArgs which i need and it does not like it.
|
|
|
|
|
Hi,
you can't just change the partameter types; Scroll gives an EventArgs, not a MouseEventArgs.
you are aware of the Control.MouseWheel event? That one offers a MouseEventArgs.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Thanks for that. You just answered my question too! lol
2 answers in 1!
Regards,
Jason Pezzimenti.
|
|
|
|
|
Thank you that was a silly thing to do.
This is the first time i have worked with events so will probably make a few mistakes along the way.
|
|
|
|
|
suppose a company has two branches in UK & US. say two windows client apps are there and they would like to transfer data to each other and their local data will be synchronozed with those data. so please guide me how can i develop a webservice which will work as a bridge and accept bulk data from client a and pass to client b vice versa. if i can get the concept then i can develop a good synchronization system by webservice. where webservice will play the role like bridge who can accept bulk data and also pass bulk data to other client.
please help me to accomplish this task.
Thanks in Advance
tbhattacharjee
|
|
|
|
|
You may want to look into the MS Sync Framework[^] before you try developing your own sync services, which Web Services are not really suited for anyway.
|
|
|
|
|
In c#, How can I hook the IE wiindow.
Can I use Hooking API's in c#?
How to use these for getting the current printer settings when a print is given from an IE window?
similarly, How to know the handles of Navigation Toolbar on IE window through windows API's?
Totally, How can I hook each and every object on IE window through c#
|
|
|
|
|
// please anyone could help me write the update code
public DataTable GetCustomers()
{
string query = "SELECT * FROM Customer_2";
SqlDataAdapter da = new SqlDataAdapter(query, constr);
DataTable table = new DataTable();
da.Fill(table);
return table;
}
// For Inserting Customers
public void InsertCustomer(string customerName)
{
string query = "INSERT INTO Customer_2 (CustomerName) VALUES (@CustomerName)";
SqlConnection con = new SqlConnection(constr);
SqlCommand com = new SqlCommand(query, con);
com.Parameters.Add("@CustomerName", SqlDbType.NVarChar).Value = customerName;
con.Open();
com.ExecuteNonQuery();
con.Close();
}
// For Deleting Customers
public void DeleteCustomers(List&lt;int&gt; customerIDsToDelete)
{
string query = "DELETE FROM Customer_2 WHERE CustomerID = @CustomerID";
SqlConnection con = new SqlConnection(constr);
SqlCommand com = new SqlCommand(query, con);
SqlTransaction tr = null;
try
{
con.Open();
tr = con.BeginTransaction();
com.Transaction = tr;
com.Parameters.Add("@CustomerID", SqlDbType.Int);
foreach (int item in customerIDsToDelete)
{
com.Parameters["@CustomerID"].Value = item;
com.ExecuteNonQuery();
}
tr.Commit();
}
catch (Exception ex)
{
tr.Rollback();
throw ex;
}
finally
{
con.Close();
}
}
// please anyone could help me write the update
|
|
|
|
|
Write what update code? The C# or SQL? How about this[^]?
only two letters away from being an asset
|
|
|
|
|
Wow! ur so rad man! i'd nvr thnk 2 bing!
[NOTE THE JOKE ICON - the norm is to use google!]
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
|
Not that I use it myself, but: DataAdapter.Update
|
|
|
|
|
Your using your DataAdapter all wrong.
It should be declared outside the scope of the GetCustomers(), so it can be accessed by all the other functions, and you should be using it to Create/Read/Updated/Delete.
How To Update a SQL Server Database by Using the SqlDataAdapter Object in Visual C# .NET[^]
NOTE: the code below has not been tested / probably wont compile because i cant spell
your code should look something like this;
private SqlDataAdapter da;
private DataSet ds;
..... somewhere in your initialization code .....
da = new SqlDataAdapter("SELECT * FROM Customer_2", [YourConnectionString]);
da.UpdateCommand = [your update command];
da.DeleteCommand = [your delete command];
da.InsertCommand = [your insert command];
public void GetCustomers()
{
da.Fill(ds);
}
public void SaveChanges()
{
da.Update(ds, "[your table name]");
ds.AcceptChanges();
}
Then all you need to do is Create/Update/Delete all the rows you want in the DataSet, just make sure you call SaveChanges().
Thats how your supposed to use the DataAdapters.
But if you still want to use it in the way that you are using it, your going to have to loop through all the rows in the DataTable and check if their RowState == DataRowState.Changed (i think, could be updated), then just run your update command against SQL.
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
Kindly would you please help me code the whole thing because it is urgent and I still want to do it my own way. Please help it is emergency, my daughter is in hospital, I have loads of tension on my mind due to her.
<code> // Dont know if this is going to be accessed outside of the class
// If so you might want to make a wrapper property for it
private SqlDataAdapter da;
// Should contain your data
private DataSet ds;
..... somewhere in your initialization code .....
da = new SqlDataAdapter("SELECT * FROM Customer_2", [YourConnectionString]);
da.UpdateCommand = [your update command];
da.DeleteCommand = [your delete command];
da.InsertCommand = [your insert command];
// dont return anything here, just fill the dataset
public void GetCustomers()
{
da.Fill(ds);
}
// Saves all the changes to the database
public void SaveChanges()
{
da.Update(ds, "[your table name]");
// Accept the changes in the dataset
ds.AcceptChanges();
}
The following is the more code for deleting from my datagridview for removal not only from datagridview but also from database as well.
List<int>customerIDsToDelete = new List<int>();
private void btnDELETE_Click(object sender, EventArgs e)
{
// Iterate all the Rows in DataGridView Rows Collection
foreach (DataGridViewRow row in dataGridView1.Rows)
{
// Get the status of CheckBox in the current Row
bool deleteStatus = Convert.ToBoolean(row.Cells[0].Value);
// Get the CashierID of the Cashier in the current row
int customerID = Convert.ToInt32(row.Cells[1].Value);
if (deleteStatus)
{
row.Selected = true;
customerIDsToDelete.Add(customerID);
}
}
// Remove From DataGridView
foreach (DataGridViewRow selectedRow in dataGridView1.SelectedRows)
{
dataGridView1.Rows.Remove(selectedRow);
}
// Remote From Database
DALHelper dal = new DALHelper();
dal.DeleteCustomers(customerIDsToDelete);
customerIDsToDelete.Clear();
// Load Cashiers from Database
LoadCustomers();
}
</code>
|
|
|
|
|
Sigh ... you are never EVER EVER going to get someone to write your project for you on here.
Regardless of your situation, sorry to hear, we all have our own problems and trying to play on our hearts is probably just going to piss more people off than anything.
I would "write" this code for you, but it seems Microsoft already has.
Case in point[^]
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
|
Go f*** yourself
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
Hi,
I am facing a problem with GridViewExtension_Demo,the problem is that every time the page is being loaded the filter grid is shaking.
Please fix my problem as soon as possible and send me the report.
I am giving the URL from where I get GridViewExtension.
DataGrid with built-in filter functionality[^]
Piyali Chowdhury
|
|
|
|