Strange LINQ to SQL behaviour (BUG?) - linq

We have this very strange issue on LINQ to SQL Code.
Consider this code snippet :
var wissen = db.Table.Where(f => f.Name == somevalue);
db.Table.DeleteAllOnSubmit(wissen);
db.SubmitChanges();
This works as expected on our dev servers, but when we are deploying this to our production server it doesn't give any errors but it doesn't delete anything neither altough it should.
When we replace this code with this :
db.ExecuteCommand("DELETE FROM Table WHERE Name = {0}", somevalue);
thing work just fine.
The workaround works just fine, but we would be happy to know what exactly goes wrong.
Looking forward to your comments :)
Dieter

Have you tried to do a SQL Profiler trace on the production machine to find out which SQL is being emitted?
This should help you troubleshoot the issue.

Is db a System.Data.Linq.DataContext? If not, try using one. If it is, call db.Log = Console.Out after instantiating, and it will send all the generated SQL to the Visual Studio output console. This should show what is going wrong.
If you can't run VS on the server, log output to a text file:
StreamWriter sw = new StreamWriter(pathToLogFile);
db.Log = sw;
// do your queries here
sw.Flush();

Related

Converting Html to Pdf with SelectPdf ArgumentNullException

iam new here and hope someone can help me out.
iam trying to convert a html string to a pdf version in net5. We had it running in net core 2.2 without any problems. Now we are trying to migrate everything to net5. Well the only part which is not working anymore is converting html string to pdf document.
We are using following nuget package: Select.HtmlToPdf.NetCore
As soon we try the convert the html string with "ConvertHtmlString" we get following Exception.
System.ArgumentNullException: 'Value cannot be null. Arg_ParamName_Name'
here is a simple snippet to repdoruce the problem:
var htmlString = "<html><head></head><body>Test me out!</body></html>";
var converter = new HtmlToPdf();
converter.Options.PdfPageSize = PdfPageSize.Letter;
converter.Options.AutoFitWidth = HtmlToPdfPageFitMode.AutoFit;
converter.Options.AutoFitHeight = HtmlToPdfPageFitMode.AutoFit;
converter.Options.PdfPageOrientation = PdfPageOrientation.Landscape;
SelectPdf.PdfDocument doc = converter.ConvertHtmlString(htmlString);
doc.Save("C:\\Temp\\test.pdf");
doc.Close();
Thanks.
Regards Maik
Ok thx for the hint in the comment..
before i posted my question i did some standard stuff i always do before researching deeper..
Clean solution, restarted VisualStudio and so on.. nothing worked.
Ive checked my nuget packages and i had the correct one installed.
I removed the package and reinstalled it again and well it works now. Cant exactly say what the problem was but.. it works now.

MVC WebAPI returning 500 error with no information

I've been having this problem for several days (now fixed and solution noted for anyone that comes across this issue and is pulling their hair out).
After my latest round of code changes to my Silverlight application which uses MVC4 WebAPI for data, I was having a problem with one of my HttpGet Actions which was returning IQueryable<oneofmyclasses>. Using Fiddler2 to watch the request, I could see I was getting an internal server error (500), with no body text to explain why. I received no errors thrown in my Action.
Check 1: I verified that my Action was indeed getting to the return collection.AsQueryable(); line with no errors. It was
Check 2: I verified that my data was serializing to JSON with no errors using this code (g is my collection):
var json = new JsonMediaTypeFormatter();
json.SerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
ObjectContent<IEnumerable<Model.MenuGroup>> responseContent = new ObjectContent<IEnumerable<Model.MenuGroup>>(g, json);
MemoryStream ms = new MemoryStream();
responseContent.CopyToAsync(ms).Wait();
ms.Position = 0;
var sr = new StreamReader(ms);
var str = sr.ReadToEnd();
This also worked. I also tested it using XML formatter even though I was pretty sure it only ever used JSON (can't be too careful).
Check 3: Enabled .Net Framework debugging. This time when the error occured (in HttpApplication.cs) VS 2012 caught it.
My error:
Despite having marked the property with these attributes,
[XmlIgnore]
[IgnoreDataMember]
[JsonIgnore]
the .Net Source was calling a get on one of my properties. The catch, it was a write-only property. I simply added
get { return null; }
and the problem was solved.
I probably should have just done Check 3 first, but my previous experience with this error has shown it to usually be an error trying to serialize my objects, which was why I had a bit of a head scratcher when they did serialize properly and the error persisted.
How I solved it:
Enabled .Net Framework debugging. Tools -> Options -> Debugging -> Check 'Enable .NET Framework source stepping'
This time when the error occured (in HttpApplication.cs) VS 2012 caught it.

CR with visual studio 2010 logon box

We are using CR with Visual studio 2010 for our applicaton.
Following is the code which I am using for generating the report from collection of objects which I got from Webservice.
SampleReport report = new SampleReport();
report.SetDataSource(response.Items);
Then at WPF level, I am assigning report source to the viewer as follows.
this.reportViewer.ViewerCore.ReportSource = report;
Problem is it is asking me login credential. Which I believe interesting as All the information to generate the report is ready to be picked up from the collection assigned as datasource.
Let me know what these credential could be. or how to override the behaviour.
Note: The designer had designed the .rpt file from xml, that WCF service provided.
I have looked around in forums for solutions, they dont have much information except following :
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
CrystalDecisions.CrystalReports.Engine.Tables CrTables ;
crConnectionInfo.ServerName = "YOUR SERVER NAME";
crConnectionInfo.DatabaseName = "YOUR DATABASE NAME";
crConnectionInfo.UserID = "YOUR DATABASE USERNAME";
crConnectionInfo.Password = "YOUR DATABASE PASSWORD";
CrTables = report.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
The problem is, I can understand if I would be connecting to DB to get the data... But getting data from object collection should not require the credential.
I faced such a problem earlier. What I did to fix this:
In the Visual Studio designer make sure that the Crystal Report Viewer doesn't have a report source defined
In the Crystal Report designer open the Field Explorer and right click on Database Fields and make sure you have selected the correct database location using the Set Database location, also try the Log On or Off Server
This is part of the code to load the report:
rptDoc.Load("CrystalReport_Test.rpt")
rptDoc.SetDataSource(rptDataset)
CrystalReportViewer1.ReportSource = rptDoc
CrystalReportViewer1.RefreshReport()
Hope this helps.

How can a client query a db4o server?

I've set up a db4o server and client. My client calls are not working.
What's puzzling to me is that the db4o examples show how the client can close the server, but not how to get and save data. See: http://community.versant.com/Documentation/Reference/db4o-7.12/java/reference/Content/client-server/networked/simple_db4o_server.htm
If I start the db4o server, and run netstat, I can see that the port is open. And on the client, I can do things like this:
Debug.WriteLine(db.Ext().IsClosed().ToString());
And that returns False, which is good.
But when I try to get or save data, it doesn't work. When saving data, it appears to work, but I don't see the data in the DB. When trying to retrieve the object, I get this error:
Db4objects.Db4o.Ext.Db4oException: Exception of type 'Db4objects.Db4o.Ext.Db4oException' was thrown. ---> System.ArgumentException: Field '_delegateType' defined on type 'Db4objects.Db4o.Internal.Query.DelegateEnvelope' is not a field on the target object which is of type 'Db4objects.Db4o.Reflect.Generic.GenericObject'.
Here are the client calls to save, then get:
Server server = new Server() { Name = "AppServerFoo" };
IObjectContainer db = GetDatabase();
db.Store(server);
db.Close();
Here's the only line in the GetDatabase() method:
return Db4oClientServer.OpenClient(Db4oClientServer.NewClientConfiguration(), "DellXps", 8484, "user", "password");
And here's the call to get from the DB:
IObjectContainer db = GetDatabase();
Server testServer = db.Query<Server>(server => server.Name == "AppServerFoo").FirstOrDefault();
db.Close();
What am I missing?
Well a server without a reference the persisted classes is a 'risky' thing. A lot of functionally doesn't work and the error which occur are cryptic. I highly recommend to always reference the assembly with the persisted classes on the server.
Another tip: Use LINQ instead of native queries. It works better and has less problems.
A ha! I got it. It took some googling, but the problem was that the server didn't have a reference to the entities. As soon as my server project referenced my client project, it worked. So, it looks like I just need to move my entities to a common project that both the client and server can reference.
Thanks to this link:
http://www.gamlor.info/wordpress/2009/11/db4o-client-server-and-concurrency/
This link looks like a gateway to having the server work without referencing the entities:
http://community.versant.com/Documentation/Reference/db4o-7.12/net2/reference/html/reference/client-server/server_without_persistent_classes_deployed.html

How do you write and debug server side actionscript?

what is the best way to write and debug Server Side Action Script on Flash Media Server?
I use Flash Builder for syntax highlighting, but that's all.
I want to debug, make breakpoints and step-trough server application code.
Any ideas?
EDIT1: I know about administration console for viewing trace messages, but that is not real debugging for me.
Although I don't know of an easy way to step through code, there are some cool things you can do.
Since objects in SSAS are dynamic, you can write a custom logging method that dumps variables recursively. I've found this very useful. If you print the method name and dump arguments with each call, this is as good as stepping through code.
Since SSAS is interpreted, you can write a custom admin console that processes eval statements. This is useful when doing live code, or debugging code in a certain state.
Here is a link to the Adobe developers guide:
http://www.adobe.com/livedocs/flashmediaserver/3.0/hpdocs/help.html?content=Book_Part_34_ss_asd_1.html
This includes the developers guide, language reference, some tutorials, etc... Everything you need to get started.
A hello world in server side ActionScript 3 looks like this:
application.onConnect = function( client ) {
client.serverHelloMsg = function( helloStr ) {
return "Hello, " + helloStr + "!";
}
application.acceptConnection( client );
}
AMS (/FMS):
Client.prototype.foo = function (){
return this;
}
Client:
netConn.call('foo', new Responder(_debug, _debug));
And breakpoint over:
function _debug(... rest):void{
}
Is as good as it gets:
we use the client to debug the server
we have to restart the server every time the main.asc file changes
we have to use rsync to upload the file to the remove machine if you can't get a local dev environment (which i couldn't - after a day of futile attempts and this post being 4 years old)
Seriously, it's load of fun, try it!

Resources