Non-printable characters being returned from oracle when using Oracle Managed DataAccess in .NET 4.5.1 - .net-4.5

We just migrated our VB.NET Web Application from .NET Framework 2.0 to 4.5.1 and as part of this migration we also updated the OLE DB driver to Oracle Managed Data Access Driver.
Turns out a few of the queries in the existing code were fetching low values (Non Printable characters, specifically chr(0).) empty string,
but the new migrated code happens to returns Non Printable character as is (returned as ""). Does any one know if this is due to migration of the Framework or the Oracle Managed Data Access Driver.
Is there a global setting/configuration that can be done to not return these "Non Printable characters". to avoid go through the code and masking the string at multiple places ?

Related

Accessing DB2-LUW 10 with entity framework 6

I am developing an application in which the database is selected by the end user at runtime. The database can either be on a MS SQL server or an IBM DB2 server. I am currently using IBM DB2 10 Express-c on a windows server for testing. I am developing using Visual Studio 2013 C# and Entity Framework 6. I have installed the EntityFramework.IBM.DB2 Nuget package for the DB2 support. I am using reverse-engineer code-first against an existing SQL server database to generate my base code. The application works fine against a SQL Server database.
I am using System.Data.Common.DbProviderFactories.GetFactory to generate the provider.
System.Data.EntityClient.EntityConnectionStringBuilder connectString = new System.Data.EntityClient.EntityConnectionStringBuilder(a_Connection);
System.Data.Common.DbConnection conn = System.Data.Common.DbProviderFactories.GetFactory(connectString.Provider).CreateConnection();
conn.ConnectionString = connectString.ProviderConnectionString;
LB500Database = new LB402_TestContext(conn, true);
a_Connection is provider=IBM.Data.DB2;provider connection string="Database=LISTBILL;User ID=xxxx;Password=yyyy;Server=db210:50000"
and is being parsed correctly by the EntityConnectionStringBuilder.
I then try to access a table in the database with
LBData500.LB_System oneSystem;
System.Linq.IQueryable<LB_System> allSystem = LB500Database.LB_System.Where(g => g.DatabaseVersion == databaseVersion && g.CompanyID == companyID);
I get an invalid operation exception "Sequence contains no matching element" which means that no elements are returned. If I remove the Where so that all rows are returned (there is one in the table) and try to enumerate the result set using the VS debugger I see the message:
"The context cannot be used while the model is being created. This exception may be thrown if the context is used inside the OnModelCreating method or if the same context instance is accessed by multiple threads concurrently. Note that instance members of DbContext and related classes are not guaranteed to be thread safe."
I am not using multi-threading. I am not inside the OnModelCreating.
Just changing the connect string to point to SQL server works fine, so I think my basic approach is sound. If I were getting some kind of error back from the server I would have something to go on. I can run the query from inside Visual Studio, so I have connectivity.
Any pointers would be appreciated.
UPDATE:
I turns out the EF objects were generated using EF5 and the EF6 runtime was being used. I regenerated the EF objects using EF6 reverse engineer code first. I can now connect to the database and get an error message:
"ERROR [42704] [IBM][DB2/NT64] SQL0204N \"DBO.LB_SYSTEM\" is an undefined name."
The schema in the DB2 database is the same as my userid (in this case, not always). I added the CurrentSchema=xxxx to the provide connection string, but EF is still passing dbo as the schema name.
Now I need a way to change the schema name at run time. I saw a link to codeplex EFModelAdapter (http://efmodeladapter.codeplex.com). So I may give that a try.
Update2 After looking through EFModelAdapter, I decided to take a different route. Since I only need database access and not schema management, I decided to go with Dapper (https://github.com/StackExchange/dapper-dot-net). This works great for what I need and allows me to change the schema name when accessing DB2 databases.
As per my Update 2, Entity Framework was a little overkill for what I needed. I switched to dapper https://github.com/StackExchange/dapper-dot-net and I am working fine against multiple DBMSs.

System.ArgumentException: The modelEntityContainerName parameter contains characters that are not valid

I've tried to use Entity Frameworks Power Tools Reverse Engineer Code First for a SQLServer database and received the following error:
System.ArgumentException: The modelEntityContainerName parameter 'testContext' contains characters that are not valid.
at System.Data.Entity.Design.EntityModelSchemaGenerator..ctor(EntityContainer storeEntityContainer, String namespaceName, String modelEntityContainerName)
at Microsoft.DbContextPackage.Handlers.ReverseEngineerCodeFirstHandler.ReverseEngineerCodeFirst(Project project)
Is there something I can do to continue or avoid this error or work around it.
Thanks.
I had the same problem. My database was named sots-version-005, and the code was not escaping the name. The answer is to rename the database, and hopefully you are in a development environment where that is easy to do.
I used SQL Management Studio, right-clicked on the database, and renamed it 'sots5', eliminating all characters except alphanumerics.
I am currently working with VS 2013 and Entity framework version 6.1.2 and ran into the same error.
I found this post by ErikEJ on Entity frameworks codeplex site:
http://entityframework.codeplex.com/workitem/898#CommentContainer9
"#Greg - This issue is not fixed in Power Tools, but is fixed in the version 6.1 Tooling (Code First from Database) (just tested with SQL Compact)"
So, currently PowerTools cannot be used for this.
However Entity framework 6 itself supports this.
Just follow the workflow described here in this video:
http://msdn.microsoft.com/en-us/data/jj200620
You add the entity data model item to the project and then choose "Code first from database".
Please note that the generated classes are a little bit different from what Power Tools would have created. Power Tools only uses Fluent API when configuring the database.
The EF wizard on the other hand uses Data annotations by default and uses Fluent API only when necessary.
However it is also possible to change the template files so that only Fluent API is used.

Entity Framework: what do I do with edmgen.exe's output?

I'm forced to use a legacy SQL Server 2000 database for an EF-based app I am writing. The tables already exist, so I need to generate the Entities layer. I can do this in VS2010 using MySQL and recent versions of SQL Server, but not 2000.
To get around this, I followed some tutorials that explain how to generate csl, msdl and ssdl files using edmgen.exe.
That works fine. I now have those files in e.g. c:\temp.
Please can someone tell me what to do with these files? I want to Entity Framework-ify a simple console application that I have written. Can I somehow create an 'ADO.NET Entity Data Model' from these files so I end up with what I would have if I had used VS2010 all along?
Thanks
I got it working, here is what I did
1) Use edmgen.exe to generate the files mentioned in my question
"C:\windows\Microsoft.NET\Framework\v4.0.30319\edmgen.exe" /mode:fullgeneration /c:"Data Source=<your_server_here>; Initial Catalog=<your_catalog_here>; UID=<username>;PWD=<password>" /project:<vs2010_project_name> /entitycontainer:<project_name>Entities /namespace:<project_name>Model /language:CSharpEntityFramework
2) Follow these instructions "How To: use your existing CSDL/MSL/SSDL files in the Entity Designer CTP2" - its actually for VS2008 but it worked for me too.
http://blogs.msdn.com/b/dsimmons/archive/2007/12/07/how-to-use-your-existing-csdl-msl-ssdl-files-in-the-entity-designer-ctp2.aspx
3) I had a further problem in that my legacy db had no primary keys so I followed these instructions which also worked
http://pratapreddypilaka.blogspot.in/2012/04/entity-framework-adding-datatable-with.html
These files are referenced in EF's connection string and EF use them at runtime to build a mapping but it can still not work because SQL Server 2000 is not supported by EF (at least EF 4.0 and newer). EF can generate SQL not supported by SQL Server 2000 and you will get exceptions at runtime.

Transaction wrapped around Enterprise Data Library code + Entity Framework code

Hey I have a unique and troubling situation.
I am working on a project where my team has used a mixture of Enterprise Data Library plus Entity Framework. Obviously this probably not recommended but it is what I'm stuck with. I would like to take a method written using Enterprise Data Library and also take a different method written using Entity Framework, and wrap both of these methods in a single transaction (without requiring Microsoft Distributed Transaction Service). I'm hoping to minimize rewriting code and be able to wrap the two methods in a single transaction just as they are. Is this possible? Thanks.
Using SQL Server 2008 and .NET 4.0
I suppose you want to mix EF and EntLib queries in the same TransactionScope, without using DTC.
Good news: it's possible. If you use exactly the same connection string for EntLib DAAB and EF DbContext, it will work, depending on the versions of EF, EntLib and SQL Server.
So what you have to do is:
check you have the right versions
get the version of your connection string changed by EF and use it instead of yours.
For 1, I have checked these combinations:
SQL Server must be 2008 or older
EntLib 4.1 + EF 5 doesn't work
EntLib 5 + EF 5 works
For 2, to get the connection string changed by EF you have to debug the execution of code that uses an instance of a DbContext. Set a breakpoint and watch or inspect the DbContext Database.Connection.ConnectionString property. That's the EF version of your connection string. Use it for both EF and EntLib and you'll get rid of DTC.

EF4, self tracking, repository pattern, SQL Server 2008 AND SQL Server Compact

I am creating a project using Entity Frameworks 4 and self tracking entities. I want to be able to either get the data from a sql server 2008 database or from sql server compact database (with the switch being in the config file). I am using the repository pattern and I will have the self tracking entities sitting in a separate assembly.
Do I need two edmx files? If so, how do I generate only one set of STE's in the separate assembly? Also do I need to generate two context classes as well? I am unsure of the plumbing for all this. Can anyone help?
Darren
I forgot to add that the two databases will be identical and that the compact version is for offline usage.
Just to follow up on this. In the end I had to maintain two separate edmx files, one for sql server and one for compact. The main reason being that compact 3.5 does not support auto identities (as mentioned above by Zeeshan). This in turn led to two context classes. In the context class for sql server compact I had to put code to check for insertions, query the database for the latest id and increment it manually before saving.
Thankfully with the release of compact 4.0 this no longer applies as it supports auto id and you can indeed use just one edmx file.
Darren
You do need the edmx file as long as the schema is exactly the same. just change the connectionstring and everything would work seamlessly. Though i am not sure how u are saying that schema is same when compact edition does not support identity concept and full blown sql server does. So if you are using features specific to sql server that's not available in compact, then you would get runtime errors.