|
Hi,
No I cant stop dropping and creating the tables. They are actually old and new jobs so they run. I need to handle it in good way.
I thought if I could check the db before I run the get method, I can easily pass through this without exception.
I dont want it to go till exception, before that only I want to handle using if else.
Is there any way that either by using the context object or by using the dbml table object on the context, I can check for existence of any table.
Any help is welcome. Thanks in advance.
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
I don't know if Linq to SQL make this information available but you can always test it "directly" if you need to. Check online help or code to see if a method exists to check for the existance.
I think that in my case I was doing an SQL query to check the existance of columns in a table when doing database upgrade. For that, you should do a google search.
As I said, handling the exception would be in my opinion the way to handle that... as even if you check the existance of the table, there is a slim chance that the table is deleted by the job between the check and the actual use of the table.
Also checking the existance explicitly will required twice as must request to update your view except if you instead write SQL stored procedure but then you won't be able to use Linq to SQL as you do.
IEnumerable<MyData> GetData()
{
IEnumerable<MyData> enumerable = null;
try
{
var query =
from m in dataContext
select m;
enumerable = query.AsEnumerable();
}
catch (SQLException ex)
{
if (ex.SomeCheck)
{
var list = new List<MyData>();
enumerable = list;
}
else
{
throw;
}
}
return enumerable;
}
You might also check : http://stackoverflow.com/questions/4520209/how-to-check-if-table-exists-in-model-but-not-in-database[^]
Or
http://leedumond.com/blog/check-if-a-table-exists-in-a-sql-server-database/[^]
Or
http://stackoverflow.com/questions/167576/sql-server-check-if-table-exists[^]
But I have warn you that if the jobs and the view run asynchronously, there is a slim chance that you could have an exception even if you do the check. That percentage will depend mainly on how often jobs are run and the duration of operation. If jobs run every few seconds and check are done at a similar rate, there is an high probabily to have an exception even with a check. On the other hand, if update are done every few hours it might take year before the problem would occurs once.
The best way is to first add the exception check and test the code. If it works and you still want to add a check anyway and don't bother with the extra SQL request, you can then add that the check being confident that the catch would get the exception in case of a bad timing.
Philippe Mori
|
|
|
|
|
Perhaps you should be posting these questions to the Linq forum.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi All,
I have created few Linq Queries using Lambda expressions in my application, and I got feedback that my Linq Queries and Lambda expressions are taking more memory. I dont know how to see that, but he told me.
Can anybody please advice me how to create Linq and Lambda expressions by consuming very less memory. I am new to the Linq and Lambda. I am giving my code below please advice me any kind of help is greatly appreciated.
Either give me idea or links to write efficient linq and lambda's or give me any alternate solution if we have other that linq and lambda.
And one more thing is that we are using Linq to SQL to connect to the database.
Below is the Code:
public string GetQuarterlyUpdateTUCDataXml( int quarterlyUpdateJobId, int quarterlyUpdateSubscriptionId)
{
string strQuarterlyUpdateDeltaReport = null;
var quarterlyUpdateSubscription = parallelDataContext.teQUTUDatas.Where(c => c.QuarterlyUpdateJobID ==
quarterlyUpdateJobId && c.QuarterlyUpdateSubscriptionID == quarterlyUpdateSubscriptionId).ToList();
if ((quarterlyUpdateSubscription != null) &&
(quarterlyUpdateSubscription.Count > 0))
{
byte[] encryptedBytes = (from a in quarterlyUpdateSubscription
join
b in parallelDataContext.teBinaryDatas on
a.DeltaReportBinaryDataID equals b.BinaryDataID
select b.Data).FirstOrDefault().ToArray();
strQuarterlyUpdateDeltaReport = (encryptedBytes != null) ?
objCommon.GetDecryptedReportString(encryptedBytes) : "";
}
return strQuarterlyUpdateDeltaReport;
}
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
indian143 wrote: I dont know how to see that, but he told me.
Who told you there were using too much memory? How did they know? Did you ask? More memory compared to what? Is it the query or the data that is taking up too much memory?
Linq does use more memory than traditional ADO.NET but there isn't much you can do about it and the trade-off is more beneficial in ease of use, maintenance, extensibility and in some cases performance.
from a in quarterlyUpdateSubscription
join b in parallelDataContext.teBinaryDatas on
a.DeltaReportBinaryDataID equals b.BinaryDataID
select b.Data
Since we have no idea what data is behind this an accurate assessment can't be made. However, if there are large sets involved here it will of course use more memory to store and perform the query and join. If you can reduce the size of the set it may help.
I know the language. I've read a book. - _Madmatt
modified on Friday, July 1, 2011 12:19 AM
|
|
|
|
|
Hi,
Thanks for the reply, its not compared to any thing. But its taking 1 GB memory my architect said. And one more thing it could be data only that is taking more memory.
Now, I will put the question in different way
Can I tune my Linq and Lambda query to select less data and use less memory so that I can improve my functions performance? Below is the code.
Thanks for any kind of help, thanks in advance.
public string GetQuarterlyUpdateTUCDataXml( int quarterlyUpdateJobId, int quarterlyUpdateSubscriptionId)
{
string strQuarterlyUpdateDeltaReport = null;
var quarterlyUpdateSubscription = parallelDataContext.teQUTUDatas.Where(c => c.QuarterlyUpdateJobID ==
quarterlyUpdateJobId && c.QuarterlyUpdateSubscriptionID == quarterlyUpdateSubscriptionId).ToList();
if ((quarterlyUpdateSubscription != null) &&
(quarterlyUpdateSubscription.Count > 0))
{
byte[] encryptedBytes = (from a in quarterlyUpdateSubscription
join
b in parallelDataContext.teBinaryDatas on
a.DeltaReportBinaryDataID equals b.BinaryDataID
select b.Data).FirstOrDefault().ToArray();
strQuarterlyUpdateDeltaReport = (encryptedBytes != null) ?
objCommon.GetDecryptedReportString(encryptedBytes) : "";
}
return strQuarterlyUpdateDeltaReport;
}
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
There was no need to post the code again.
As I stated, there may be a way to reduce the size but I have no idea of the data structure or your requirements. Maybe your architect would be the one to ask
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
For a method returning a single string, this is rather wasteful: you bring in a list of items in memory (with a call of ToList() ), then run a join, but then you throw away all but the first item of the result!
You don't need a list of teQUTUData objects in memory: all you use is their DeltaReportBinaryDataID column, so select only that column in your first LINQ query (add .Select(a => a.DeltaReportBinaryDataID) to the first query).
Next, you don't need a join in your second query: it's an in-list lookup. Rewrite your query to run a select from parallelDataContext.teBinaryDatas, where quarterlyUpdateSubscription contains b.BinaryDataID.
This should do the trick. Good luck!
|
|
|
|
|
Hi,
Your post has helped me greatly. I really appreciate your help. I am really greatfull for this help. You not only helped me in solving the problem but also helped me in understanding the usage of select in the linq. Thats where real puzzle there I think so.
Once select is understood then Linqs become easy I think.
In all the ways this help is really appreciable. Thanks a lot again.
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
|
Download LINQPad a free tool that will allows you to test your queries.
This tool is really helpfull to optimize your query because it will display the time it takes to executed code. Also, it is possible to see the generated SQL. Anytime the SQL seems way too complex or the number of queries is large, you should try to see it it can be improved.
http://www.linqpad.net/[^]
Also since the tool nicely display the result, it is possible to validate visually that your queries make senses. For example if hte number of returned rows is bigger than expected, a WHERE clause might be missing.
This tool is a must have. It may it easy to compare alternative queries. Also a lot of sample come with the tool and show different thing like how to do grouping, how to test NULL value in a database and more.
Sometime a simple difference like exchanging SingleOrDefault() with FirstOrDefault() can make a huge difference in the query even though the result would be the same (apart that in one case it would have been check that a single item exists.
Also it will help to spot iterative requests. That is when a query would cause a first request then repeat another sub-request for each element. Sometimes, it might be preferable to explicitly make 2 simpler requests that LINQ to SQL would be able to translate in 1 SQL request each instead of a big request that would result in mlutiple request.
Philippe Mori
|
|
|
|
|
LINQ queries are executed only when results are required to be used in the code.
ToList() and
ToArray() force the queries to execute since the results are to be stored in the respective list and array. If the query is large enough, then it sure will consume huge memory. As dasblinkenlight already suggested, rewrite your query to select only the rows and columns that you actually require instead of loading the entire table and reading the required row/column.
|
|
|
|
|
Hi,
I was using LinqToExcel.dll file before in my win 32 bit machine and was working fine. Now when i try my project(asp.net) in win 64 bit, it gave error because of this LinqToExcel.dll file. Is there any equivalent file for LinqToExcel.dll file for win64 bit? Does anybody have any ideas or suggestions??
suchita
|
|
|
|
|
SayamiSuchi wrote: it gave error
How many times do we hear this? And the the response is the same.
What error!?! If you want help you must provide sufficient details.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
in my local machine, since its 32 bit, i can't see the error. But because of that file, it is not running in 64 bit machine..
suchita
|
|
|
|
|
Post here your exception message.
Parwej Ahamad
ahamad.parwej@gmail.com
|
|
|
|
|
If you can't see an error then how can you be sure it is this file? What debugging or diagnostics steps have you taken to isolate this file as the problem?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
|
I am using visual studio 2010.
and i have html file which can be readed.
so i changed html file to asp(only change file extension).
But after that, i can't read asp.
Web page only show "This type of page is not served."
How can i read asp file?
(I am using windows7 64bit ans visual studio 2010).
hi
My english is a little.
anyway, nice to meet you~~
and give me your advice anytime~
|
|
|
|
|
The problem isn't with VS, it can "read" many types of files. To view an asp file in the browser it must be hosted in IIS, the development web server with VS won't work.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Tanks for your reply.
Have a nice day!
hi
My english is a little.
anyway, nice to meet you~~
and give me your advice anytime~
|
|
|
|
|
5 - correct answer.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Hi,
I am working on an existing page1.aspx page
It has <asp:UpdatePanel with dropdownList controls inside it.
In this page there is also a usercontrol which has a hyperlink which allows
the user to be redirected to page2.aspx.
i.e. XXXX.NavigateUrl = "Page2.aspx?somevaluesXXX
On Page2.aspx, there is a backbutton which should take you to the previous page i.e.
page1.aspx in this case.
How do I go back to the previous page i.e. page1.aspx with the optioins I selected in my dropdowns in page1.aspx?
At present I have this javascript on the click of goback button
but it does not work.
BtnBack.Attributes.Item("onclick") = "history.back(1);return false"
What needs to be done please?
Thanks
|
|
|
|
|
You need to persist the settings in some fashion, either by passing them via the query string or storing in session state, so the form can be reset using these values.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I want to fill gridview textbox by selecting data from gridview Dropdownlist
|
|
|
|