2017-04-01 277 views
1

我嘗試部署一個簡單的wcf服務,它與mysql5.7數據庫通過錯誤斷開連接,但是當我運行到我的本地機器時它工作正常(我的本地機器也有一個mysql5.7數據庫)我不知道爲什麼會出現這個錯誤。異常消息是'無法加載文件或程序集'MySql.Data,Version = 6.9.9.0,Culture = neutral,PublicKeyToken = c5687fc88969c44d'?

我都準備好了添加Mysql.Data.dll 6.9.9.0;

錯誤是:

服務器在處理請求時遇到錯誤。異常消息是

「無法加載文件或程序集‘MySql.Data,版本= 6.9.9.0, 文化=中性公鑰= c5687fc88969c44d’或它 的一個依賴。該系統找不到指定的文件。'。有關更多詳細信息,請參見服務器 日誌

。的異常堆棧跟蹤是:

在MyServiceBecouseError.MyNameService.nameInput(字符串輸入,字符串 inputwo)在SyncInvokenameInput在 System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(對象,對象[],對象[]) (對象 例如,對象[]輸入,對象[] &輸出)在 System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc & RPC)在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc & RPC)在 System.Serv iceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc & RPC)在System.ServiceModel.Dispatcher.MessageRpc.Process(布爾 isOperationContextSet)

我的web.config文件:在

<configuration> 
    <system.serviceModel> 

    <behaviors> 
     <endpointBehaviors> 
     <behavior name="web"> 
      <webHttp/> 
     </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
     <behavior name="mexBehaviors"> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 

    <services> 
     <service name="MyServiceBecouseError.MyNameService" behaviorConfiguration="mexBehaviors"> 
     <endpoint address="" binding="webHttpBinding" behaviorConfiguration="web" contract="MyServiceBecouseError.IMyNameService"/> 
     </service> 
    </services> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
    <system.webServer> 
    <directoryBrowse enabled="true"/> 
    </system.webServer> 
    <system.web> 
    <compilation debug="true"/> 
    </system.web> 
<runtime> 
    <dependentAssembly>         
    <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" /> 
    <bindingRedirect oldVersion="0.0.0.0" newVersion="6.9.9.0" /> 
</dependentAssembly> 
</runtime> 
</configuration> 

簡單的方法連接數據庫並將數據插入數據庫的應用程序;

public class MyNameService : IMyNameService 
    { 


     public string nameInput(string input, string inputwo) 
     { 
      string myDataString = "Server=localhost;Database=foo;Uid=root;Pwd=qwerty;"; 

      MySqlConnection connection = new MySqlConnection(myDataString); 
      MySqlCommand cmd; 
      connection.Open(); 
      try 
      { 
       cmd = connection.CreateCommand(); 
       cmd.CommandText= "INSERT INTO foo.footable (id,name,lastName) VALUES (@id,@name,@lastName)"; 
       cmd.Parameters.AddWithValue("@id", int.Parse(3.ToString())); 
       cmd.Parameters.AddWithValue("@name", input); 
       cmd.Parameters.AddWithValue("@lastName", inputwo); 
       cmd.ExecuteNonQuery(); 
       connection.Close(); 
      } 
      catch (Exception e) 
      { 
       Console.WriteLine(e.Message); 
      } 
      return "hello pushpam"; 
     } 

    } 
} 

回答

0

.net框架版本是否與IIS應用程序池相符?

相關問題