ADO.NET EF - can't establish DB connection using VS2010 - visual-studio-2010

I'm following this tutorial : http://msdn.microsoft.com/en-us/data/jj193542 for Code First basics using ADO.NET EF. The problem is that when executing the code the DataBase is not created automatically and I think that this is because the configurations in my app.config but it's my first day with real code and I can't figure out how to adjust my config file so I can connect to my server and use a created DataBase if neccessary or let the program from the tutorial create new database as expected from what is written.
This is my App.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<!-- <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory> -->
<connectionStrings>
<add name="BloggingContext"
providerName="System.Data.SqlClient"
connectionString="server=milka-pc\sqlserver2012;Database=Panorama;user id=MyID;password=MyPass;port=3333;Integrated Security=True;"/>
</connectionStrings>
<!--<contexts>
<context type=" Blogging.BloggingContext, MyAssembly">
<databaseInitializer type="Blogging.MyCustomBlogInitializer, MyAssembly" />
</context>
</contexts>-->
</entityFramework>
</configuration>
As you can see some parts are commented as I tried a various things to make it work.
This is how y server explorer looks like while I'm trying to connect:
Also since I have zero experience with ViasualStudioXXXX and connecting to DataBases this is what I see and how I select my server:
There in milka-pc\sqlserver2012 I have a DB named Panorama which I can use or better follow the tutorial step by step and leave the program to create my new DB. For now I can't neither of these two. And to connect to milka-pc\sqlserver2012 I need to provied UserName and Password which I did in App.config. I say this just to know that these fields are not blank

If you are sure that milka-pc\sqlserver2012 is in fact working on port 3333 as you suggested
change your connectionstring to this:
<add name="BloggingContext"
providerName="System.Data.SqlClient"
connectionString="server=milka-pc\sqlserver2012,3333;Database=Panorama;user id=MyID;password=MyPass;Integrated Security=True;"/>
Just to make sure try that connection string in you SQL management studio with provided credentials.
If that doesnt work consult your sql server configuration manager, specifically under SQL server Network configuration make sure that your instance has enabled TCP/IP pipe with appropriate port enabled.
Cheers.

Related

No Entity Framework provider found for the ADO.NET provider with invariant name 'Oracle.ManagedDataAccess.Client' . How to solve this error?

Summary: How to solve this error when generating database from model with Entity Framework and Oracle?
Details:
I tried researching and I realize there are similar questions here (like this one: No Entity Framework provider found for the ADO.NET provider with invariant name 'MySql.Data.MySqlClient' - WCF ) but my case seems to be different.
I'm new to Entity Framework and I'm making a custom destination component for a SQL Server Integration Services (SSIS), an ETL tool. I am using a previously developed destination component as a template that used LINQ to SQL and was aimed at SQL Server. I decided to switch to Entity Framework since my component is for Oracle.
After various attempts installing and uninstalling, I managed to use ODAC and ODT for Visual Studio (I'm using VS 2017 community) according to this: https://community.oracle.com/message/14535771#14535771
When I tried to create an edmx file from my DB, I followed http://download.oracle.com/oll/obe/EntityFrameworkOBE/EntityFrameworkOBE.htm#t8 , although it seems to use an older version. My wizard process looked like this:
Model from DB. I'm not sure what's the real difference between Designer and Code First...
Choose EF version. Although I did install the latest version of EF using NuGet, I get this message. I previously couldn't even generate the edmx because of an EF version error until I followed the instructions in the first link of this message.
After successfully generating the edmx model, after editing it, I tried to
"Generate Database From Model...", but then I get this error.
I'm pretty sure I registered to GAC when installing ODAC, though I'm not sure how to verify that. That might also be a problem since the ODAC installation wizard tells me to not do that when using NuGet, although I have to if I want to use ODT for Visual Studio properly AFAIK.
As I said, I'm new to EF, so I'm not sure how my App.config should look like, but currently it looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="Oracle.ManagedDataAccess.Client" />
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
</system.data>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<publisherPolicy apply="no" />
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
<bindingRedirect oldVersion="4.121.0.0 - 4.65535.65535.65535" newVersion="4.122.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<oracle.manageddataaccess.client>
<version number="*">
<dataSources>
<dataSource alias="SampleDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=xe))) " />
</dataSources>
</version>
</oracle.manageddataaccess.client>
<connectionStrings>
<add name="GerenciadorExpurgoEF" connectionString="metadata=res://*/Models.GerenciadorExpurgoEF.csdl|res://*/Models.GerenciadorExpurgoEF.ssdl|res://*/Models.GerenciadorExpurgoEF.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string="DATA SOURCE=PurgeDB;PASSWORD=TESTUSR;PERSIST SECURITY INFO=True;USER ID=TESTUSR"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
What worked for me was copying the App.config from my .NET Framework EF project into my .NET Core MVC project.
That, and as many other people have suggested on other questions, EF and the Oracle EF provider need to be installed in both projects (or at least referenced).

ODP.NET + Unexpected traffic on port 6200 (Oracle Notification Services)

We've got a client using our product, which includes a windows service built using .NET 4+, Entity Framework, and ODP.NET. For some reason in one particular installation, but not any other, the windows service appears to be generating traffic on 6200. Oracle Documentation indicates this is the port Oracle Notification Services uses. This is unexpected because our product does not utilize ONS. I've found other Oracle Documentation that indicates that RAC / Fast Failover also uses ONS, but we've confirmed with the client that they do not use RAC in any environments, and we are not using the RAC options in the connection string. We are also not (to our knowledge) using Database Change Notifications or doing any cache/verification of cached data, which it sounds like also leverages ONS.
Can anyone help explain why we would be generating port 6200 traffic, and more importantly, how to get it to stop? Thanks!
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings [Redacted] />
<appSettings [Redacted] />
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</providers>
<contexts>
<context type="[Redacted]" disableDatabaseInitialization="true" />
</contexts>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="Oracle.ManagedDataAccess.Client" />
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
</system.data>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" />
</runtime>
</configuration>
We've narrowed the culprit down to one or more of 3 Oracle / ODP.NET specific Connection String settings:
ENLIST, HA EVENTS, and/or LOAD BALANCING
Oracle's documentation on Fast Application Notification tipped us off to these settings which we had not been aware of. This lead us to Oracle's documentation on all of their Feature Connection String Attributes.
Enlist - Default "true" - Serviced components automatically enlist in
distributed transactions.
HA Events - Default "false" - Enables ODP.NET connection pool to
proactively remove connections from the pool when a RAC service,
service member, or node goes down.
Load Balancing - Default "false" - Enables ODP.NET connection pool to
balance work requests across RAC instances based on the load balancing
advisory and service goal.
We set all 3 to explicitly be false, and the port 6200 connections ended.
ENLIST=false; HA EVENTS=false; LOAD BALANCING=false;
If the defaults are to be believed then Enlist was the culprit, but client's availability did not allow for discrete testing to confirm. We've come across other various documentation linking all 3 of these pieces of functionality to Oracle Notification Services & port 6200.
It may depend on the installed Oracle client version. In 12.1.0.2 auto-configuration of ONS feature was released. It may have something like ONS auto-discovery at the beginning of establishing a DB connection which produces this traffic.

ADO.NET EF - can't connect to my DB (using Visual Studio 2010)

So I'm struggling with this problem for more than 4 hours and I don't know where to look at any more. I follow this tutorial for absolute beginners in ADO.NET Entity Framework - [See The tutorial][1] [1]: http://msdn.microsoft.com/en-us/data/jj193542
I'm using Microsoft SQL Server 2012 and I'm using this App.Config file for my project :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=sqlserver2012; Integrated Security=True; MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
</configuration>
But I keep getting errors and when I use this code the error is : **An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string.**
I'm totally new to ADO.NET Entity Framework but as I see it the problem maybe is in defaultConnectionFactory configuration. But anyways I can't find out how to keep on and how to solve this problem.
if you in fact have SQL Server instance named sqlserver2012 on your localhost zour connectionString should look like this
<parameter value="Data Source=localhost\sqlserver2012; Integrated Security=True; MultipleActiveResultSets=True" />
Cheers,
T.

Error Debugging MVC 3 after Publish

I had done one publish to my MVC application. After that, I cannot debug it anymore!
This is the error. It seems that my visual studio web server is loading machine.config
Server Error in '/' Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty.
Source Error:
Line 255:
Line 256:
Source File: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config Line: 257
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237
This is how my web.config looks like, and there is nothing in my code that uses ASP.Net Membership as my authentication mode is "Windows".
I did manage to run it again in Visual Studio once, after I set the build mode from "Release" to "Debug" vice versa, but after I published again today.. The problem came back.
<configuration>
<connectionStrings>
<clear/>
<add name="ApplicationServices" connectionString="Data Source=SCG1SQL-64;Initial Catalog=Metallurgy;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="mandb100ConnectionString" connectionString="Data Source=scg1sql-64;Initial Catalog=mandb100;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="1.0.0.0" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<authentication mode="Windows"/>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</configuration>
Well, it is using the machine.config. There is a hierarchy of configuration. In other words, if you don't explicitly specify (or remove or clear) in your web.config, the base defaults will be pulled from the machine.config.
What your ASP.NET application will do is look for a web.config in the current directory for configuration. If that isn't found, or the desired configuration isn't found, it'll look to the application's web.config. Then for defaults, or uncleared or nonremoved items it'll also pull configuration from the machine.config.
But to the problem. What your error message is saying is that it can't find the LocalSqlServer connection string name anywhere. Are you sure that conn string name exists in your web.config?
Edit: Check your web.release.config file. You can find it in your Solution Explorer if you drop down the web.config file. Does that perhaps contain LocalSqlServer connection string?
This link might be of help: http://msdn.microsoft.com/en-us/library/webmatrix.webdata.preapplicationstartcode(v=vs.99).aspx
That's how I solved my problem. Apparently, this WebMatrix SimpleMembership is enabled by default. So I added this line in my web.config, and the problem disappeared!!!
<add key="enableSimpleMembership" value="false"/>
I know this is an old post, and as both these answers are correct to point you in the right direction to solve the issue, I'd like to add another solution if it might help anyone.
In my application an error occurred after I used the "Add Deployable Dependencies..." item in Solution Explorer, project context menu (right click on a project). This added a directory called _bin_deployableAssemblies with dlls needed to deploy your application on a server if it doesn't have some of them added to GAC. The dlls in the _bin_deployableAssemblies are copied to the bin directory of your application.
There were two dlls of interest that I wasn't using WebMatrix.Data and WebMatrix.WebData. Their presence in the bin directory of my application somehow messes the default membership provider resolving (correct me if I'm wrong, or add an explanation to what really happens :) ). The solution was to simply remove the offending dlls from the bin directory and from the _bin_deployableAssemblies as well.

Newbie in MVC3 connection setup

I'm a real newbie in MVC3 but excited to learn. Guide me how to change connection from App_Data (DB.mdf) to MS SQL Server 2008.
MDF connection
<add name="MvcMusicStoreEntities" connectionString="metadata=res://*/Models.MusicStore.csdl|res://*/Models.MusicStore.ssdl|res://*/Models.MusicStore.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MvcMusicStore.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
This is a working one from my running project:
<add name="CONNECTION_NAME" connectionString="data source=SQL_SERVER_IP\INSTANCE_NAME; User ID=SQL_USER_NAME; Password=YOUR_PASSWORDd;Initial catalog=DB_NAME" providerName="System.Data.SqlClient" />
for your posted one, it may look like this:
as I can see, you are not following the MVC3 version of music store, or that's how it look for me as I've checked the PDF file of the MVC3 vesion and found that Jon Galloway is using the connecion string just like the one I'm using.
check out the PDF from here: http://mvcmusicstore.codeplex.com/releases/view/59112#DownloadId=197609
That's it, no other parts are required.
this is also a very very nice resource for you to find the different ways that you can do to configure your app connection string.
http://www.connectionstrings.com/sql-server-2008
From SQL Server 2008 connection strings
Data Source=myServerAddress;
Initial Catalog=myDataBase;
User Id=myUsername;
Password=myPassword;
Example:
<add name="NAME" connectionString="Data Source=.\SQLExpress; User ID=username; Password=password;Initial catalog=database" providerName="System.Data.SqlClient" />
If you are going to use Entity Framework you need to change the provider to
providerName="System.Data.EntityClient"
And modify the add tag:
<add name="Entities" connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLExpress;Initial Catalog=Test;Persist Security Info=True;User ID=test;Password=test;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient"/>

Resources