Строка подключения не обнаруживается в объектах ADO.NET
Я впервые попробовал модель сущности ADO.Net Data и хотел бы работать с ней на linq. Я проверил соединение с сущностью и следующий код для проверки соединения:
Public Function SaveContact(ByVal ContactValue As Contact, ByVal IsNew As Boolean) As String Implements IContactService.SaveContact
Dim db As New salessolEntities
db.Database.Connection.Open()
db.Database.Connection.Close()
Return Nothing
End Function
Однако я получаю следующую ошибку:
Строка подключения с именем 'salessolEntities' не найдена в файле конфигурации приложения.
Строка подключения правильно установлена в app.config: Версия по умолчанию (автоматически генерируется):
<connectionStrings>
<add name="SalesSolWcfLib.My.MySettings.DBConnection" connectionString="server=localhost;User Id=root;password=surpavan;database=salessol;Persist Security Info=True;Old Guids=True" providerName="MySql.Data.MySqlClient" />
<add name="salessolEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=MySql.Data.MySqlClient;provider connection string="server=localhost;user id=root;password=surpavan;database=salessol;persist security info=True;old guids=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
Небольшая модификация:
<connectionStrings>
<add name="SalesSolWcfLib.My.MySettings.DBConnection" connectionString="server=localhost;User Id=root;password=surpavan;database=salessol;Persist Security Info=True;Old Guids=True" providerName="MySql.Data.MySqlClient" />
<add name="salessolEntities" connectionString="server=localhost;User Id=root;password=surpavan;database=salessol;Persist Security Info=True;Old Guids=True" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
Еще одна модификация:
<connectionStrings>
<add name="SalesSolWcfLib.My.MySettings.DBConnection" connectionString="server=localhost;User Id=root;password=surpavan;database=salessol;Persist Security Info=True;Old Guids=True" providerName="MySql.Data.MySqlClient" />
<add name="SalesSolWcfLib.My.MySettings.salessolEntities" connectionString="server=localhost;User Id=root;password=surpavan;database=salessol;Persist Security Info=True;Old Guids=True" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
Весь App.config:
<?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=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="SalesSolWcfLib.My.MySettings.DBConnection" connectionString="server=localhost;User Id=root;password=surpavan;database=salessol;Persist Security Info=True;Old Guids=True" providerName="MySql.Data.MySqlClient" />
<add name="SalesSolWcfLib.My.MySettings.salessolEntities" connectionString="server=localhost;User Id=root;password=surpavan;database=salessol;Persist Security Info=True;Old Guids=True" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<system.web>
<compilation debug="true" />
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="SalesSolWcfLib.Service1">
<endpoint address="" binding="basicHttpBinding" contract="SalesSolWcfLib.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/SalesSolWcfLib/Service1/" />
</baseAddresses>
</host>
</service>
<service name="SalesSolWcfLib.ContactService">
<endpoint address="" binding="basicHttpBinding" contract="SalesSolWcfLib.IContactService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/SalesSolWcfLib/ContactService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
</configuration>
Посоветуйте, пожалуйста, в какой части я ошибся, это проект WCF с Mysql. Мое ручное соединение с "SalesSolWcfLib.My.MySettings.DBConnection" работает хорошо, но с ado.net я сталкиваюсь с этой проблемой. Пожалуйста, поправьте меня, где я ошибся.