在ADO.NET实体中未检测到连接字符串

时间:2013-11-17 01:43:58

标签: vb.net wcf ado.net mysqlconnection

我第一次尝试了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=&quot;server=localhost;user id=root;password=surpavan;database=salessol;persist security info=True;old guids=True&quot;" 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>

Tables That got picked up

整个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>

请告知我哪个部分出错了,这是一个带有Mysql的WCF项目。我与“SalesSolWcfLib.My.MySettings.DBConnection”的手动连接效果很好,但是对于ado.net我正面临这个问题。请纠正我错误的地方。

0 个答案:

没有答案