Subsonic: Using SharedDbConnectionScope together with TransactionScope seems to be broken - c#

Using the code below, the expected behavior is that the database won't reflect the update since ts.Complete() is never called but the updates seems to go through. But if I leave out the SharedDbConnectionScope then the expected behavior is seen. Is there a problem with SharedDbConnectionScope? Btw I am using Subsonic 2.2
using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope())
{
using (TransactionScope ts = new TransactionScope())
{
// update here
}
}

Found out the problem. The docs on Subsonic appears to be wrong. If I wrap TransactionScope over SharedDbConnectionScope then it works fine. The right way should be:
using (TransactionScope ts = new TransactionScope())
{
using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope())
{
// update here
}
}
Edit: As mentioned by firestorm, SharedDbConnectionScope doesn't seem to work in Subsonic 2.2. So the only solution seems to be to install MsDts and don't use SharedDbConnectionScope.

I don't think SharedDbConnectionScope works at all in Subsonic 2.2.
The whole idea as far as I can see with the object is that when you use it you don't need to have MsDts installed on the server. I couldn't get this to work at all!
When you install MsDts then you don't need SharedDbConnectionScope any more that's why your code works when it gets created after TransactionScope.

Related

Telerik OpenAccess ORM with SQL Server 2005

I'm trying out this ORM & new to this. I have following code:
IObjectScope scope = Database.Get("MyConnection").GetObjectScope();
try
{
scope.Transaction.Begin();
Reading r = new Reading();
r.ReadingURL = reading.ReadingURL;
r.IsActive = true;
scope.Add(r);
scope.Transaction.Commit();
}
finally
{
scope.Dispose();
}
When I run this I get following error on "Add":
Telerik.OpenAccess.Exceptions.InvalidOperationException: Class
'WritingChallenge.Reading' is persistent but not known in this
context.
It seems for some reason database connection is lost? I'm not sure what is the issue here.
The issue here is that the model that was connected to the WritingReplacementConnection was having no information about the WritingChallenge.Reading type.
Did you specify a mappingConfiguration that included this type?
You can also ask this kind of questions in the forums at Telerik Forums - .NET ORM.

C# code completion with NRefactory 5

I just found out about NRefactory 5 and I would guess, that it is the most suitable solution for my current problem. At the moment I'm developing a little C# scripting application for which I would like to provide code completion. Until recently I've done this using the "Roslyn" project from Microsoft. But as the latest update of this project requires .Net Framework 4.5 I can't use this any more as I would like the app to run under Win XP as well. So I have to switch to another technology here.
My problem is not the compilation stuff. This can be done, with some more effort, by .Net CodeDomProvider as well. The problem ist the code completion stuff. As far as I know, NRefactory 5 provides everything that is required to provide code completion (parser, type system etc.) but I just can't figure out how to use it. I took a look at SharpDevelop source code but they don't use NRefactory 5 for code completion there, they only use it as decompiler. As I couldn't find an example on how to use it for code completion in the net as well I thought that I might find some help here.
The situation is as follows. I have one single file containing the script code. Actually it is not even a file but a string which I get from the editor control (by the way: I'm using AvalonEdit for this. Great editor!) and some assemblies that needs to get referenced. So, no solution files, no project files etc. just one string of source code and the assemblies.
I've taken a look at the Demo that comes with NRefactory 5 and the article on code project and got up with something like this:
var unresolvedTypeSystem = syntaxTree.ToTypeSystem();
IProjectContent pc = new CSharpProjectContent();
// Add parsed files to the type system
pc = pc.AddOrUpdateFiles(unresolvedTypeSystem);
// Add referenced assemblies:
pc = pc.AddAssemblyReferences(new CecilLoader().LoadAssemblyFile(
System.Reflection.Assembly.GetAssembly(typeof(Object)).Location));
My problem is that I have no clue on how to go on. I'm not even sure if it is the right approach to accomplish my goal. How to use the CSharpCompletionEngine? What else is required? etc. You see there are many things that are very unclear at the moment and I hope you can bring some light into this.
Thank you all very much in advance!
I've just compiled and example project that does C# code completion with AvalonEdit and NRefactory.
It can be found on Github here.
Take a look at method ICSharpCode.NRefactory.CSharp.CodeCompletion.CreateEngine. You need to create an instance of CSharpCompletionEngine and pass in the correct document and the resolvers. I managed to get it working for CTRL+Space compltition scenario. However I am having troubles with references to types that are in other namespaces. It looks like CSharpTypeResolveContext does not take into account the using namespace statements - If I resolve the references with CSharpAstResolver, they are resolved OK, but I am unable to correctly use this resolver in code completition scenario...
UPDATE #1:
I've just managed to get the working by obtaining resolver from unresolved fail.
Here is the snippet:
var mb = new DefaultCompletionContextProvider(doc, unresolvedFile);
var resolver3 = unresolvedFile.GetResolver(cmp, loc); // get the resolver from unresolvedFile
var engine = new CSharpCompletionEngine(doc, mb, new CodeCompletionBugTests.TestFactory(resolver3), pctx, resolver3.CurrentTypeResolveContext );
Update #2:
Here is the complete method. It references classes from unit test projects, sou you would need to reference/copy them into your project:
public static IEnumerable<ICompletionData> DoCodeComplete(string editorText, int offset) // not the best way to put in the whole string every time
{
var doc = new ReadOnlyDocument(editorText);
var location = doc.GetLocation(offset);
string parsedText = editorText; // TODO: Why there are different values in test cases?
var syntaxTree = new CSharpParser().Parse(parsedText, "program.cs");
syntaxTree.Freeze();
var unresolvedFile = syntaxTree.ToTypeSystem();
var mb = new DefaultCompletionContextProvider(doc, unresolvedFile);
IProjectContent pctx = new CSharpProjectContent();
var refs = new List<IUnresolvedAssembly> { mscorlib.Value, systemCore.Value, systemAssembly.Value};
pctx = pctx.AddAssemblyReferences(refs);
pctx = pctx.AddOrUpdateFiles(unresolvedFile);
var cmp = pctx.CreateCompilation();
var resolver3 = unresolvedFile.GetResolver(cmp, location);
var engine = new CSharpCompletionEngine(doc, mb, new CodeCompletionBugTests.TestFactory(resolver3), pctx, resolver3.CurrentTypeResolveContext );
engine.EolMarker = Environment.NewLine;
engine.FormattingPolicy = FormattingOptionsFactory.CreateMono();
var data = engine.GetCompletionData(offset, controlSpace: false);
return data;
}
}
Hope it helps,
Matra
NRefactory 5 is being used in SharpDevelop 5. The source code for SharpDevelop 5 is currently available in the newNR branch on github. I would take a look at the CSharpCompletionBinding class which has code to display a completion list window using information from NRefactory's CSharpCompletionEngine.

ODP.NET memory leak when using UDT:s

When using ODP.NET load data into and spatial database i'm using UDT to define the SDOGEOMETRY type.
Then i use the ArrayBindCount on the OracleCommand to load batches of data. Everything works, but i see a constant increase of memory of the process, and performance counters shows the same thing..
Parameter is created using:
var param = new OracleParameter("geom", OracleDbType.Object);
param.UdtTypeName = "MDSYS.SDO_GEOMETRY";
param.Direction = ParameterDirection.Input;
cmd.Parameters.Add(param);
Also, i set the cmd.AddToStatementCache = false to prevent data from ending up in there..
When adding data i use:
param.Value = new object[numRowsToInsert];
int row = 0;
foreach (var row in rowstoinsert)
{
OracleUDT.SdoGeometry geoVal = rowstoinsert[row].geom;
(param.Value as object[])[row] = geoval;
}
...
cmd.ExecuteNonQuery(); //THIS IS WHERE MEMORY LEAK APPEARS TO BE
..
I tried running the program with ExecuteNonQuery() removed, and then there is no MemoryLeakage at all....
Edit:
I also tried removing the UDT-parameter and run through the program, also without any leak. So it looks the problem is very close related to UDT:s and when statements are executed.
I'm using ODP.NET 11.2.0.2.1
Anyone got any clue?
Is there something i need to clean that does not get created if not running ExecuteNonQuery()?
Thought I'd give a followup on this one.
After numerous emails with Oracle Tech-Support i finally got this accepted as a bug
This appears to be Bug 10157396 which is fixed in 12.1, is planned to be fixed in 11.2.0.4 and has been backported to 11.2.0.2 (available in Patch Bundle 18). This can be downloaded from MyOracleSupport as Patches 10098816 (11.2.0.2) and 13897456 (Bundle 18) for a temporary solution while we get a backport to 11.2.0.3 or until 11.2.0.4 is released.

NoRM UpdateOne no work

I'm using NoRM + MongoDB in an application test. I found the source code of the Mongo Session http://normproject.org/samples where the method update wrapp this:
using(var db = Mongo.Create(_connectionString))
{
db.GetCollection<T>().UpdateOne(item, item);
}
But when I send object to update using this method my object no save, but what if I call Save instead of UpdateOne my object is save.
My objects: https://gist.github.com/1616565
What's wrong?
Hopefully this helps:
http://groups.google.com/group/norm-mongodb/browse_thread/thread/8ba8b462b6fe16a5/a4bfaecef4b1cbfc?lnk=gst&q=Update#a4bfaecef4b1cbfc
Anup
I would recommend using the official C# driver, which you can find at:
http://www.mongodb.org/display/DOCS/CSharp+Language+Center

subsonic in visual studio design host

I'm facing currently a problem regarding Subsonic configuration.
What I want to achieve is using subsonic data access in a System.Web.UI.Design.ControlDesigner class.
This class is hosted in Visual Studio Environment and enables design time operations on the attached System.Web.UI.WebControls.Control.
The only problem is SubSonic seems always looking for SubSonicSection in the application configuration regardless passing connection string to it.
The relevant code snippet:
using (SharedDbConnectionScope dbScope = new SharedDbConnectionScope(new SqlDataProvider(), ConnectionString))
{
Table1 _table1 = new Select().From<..().Where(...).IsEqualTo(...).ExecuteSingle<...>();
Throws exception on ExecuteSingle() method (configuration section was not found)
while
using (SharedDbConnectionScope dbScope = new SharedDbConnectionScope(ConnectionString))
{
Throws exception on new SharedDbConnectionScope() (configuration section was not found)
So the question is:
Is there any way to pass the settings runtime to bypass the configuration section lookup as I don't want to add any subsonic specific configuration to devenv.configuration
Thanks
I don't think you can do this in 2.x without customising the templates (which can obviously give support issues when a newer version of SubSonic is released).
Sorry, don't know about 3.0
I'm assuming you're using SubSonic 2.x based on your query syntax. Have a look at the following two forum posts which should point you in the right direction. What you're trying to do is possible, in fact SubCommander does exactly this, download the source and have a look at the SetProviderManually() method.
http://forums.subsonicproject.com/forums/t/1617.aspx
http://forums.subsonicproject.com/forums/t/1502.aspx
The method to use Subsonic runtime provider configuration:
(example):
private void SetSubsonicProviderManually(string ConnectionString)
{
//clear the providers and reset
DataService.Provider = new SqlDataProvider();
DataService.Providers = new DataProviderCollection();
//instance a section - we'll set this manually for the DataService
SubSonicSection section = new SubSonicSection();
section.DefaultProvider = __SubsonicProviderName__;
//set the properties
DataProvider provider = DataService.Provider;
NameValueCollection config = new NameValueCollection();
//need to add this for now
config.Add("connectionStringName", __ConnectionString__);
//initialize the provider
provider.Initialize(__SubsonicProviderName__, config);
provider.DefaultConnectionString = ConnectionString;
DataService.Providers.Add(provider);
}

Categories

Resources