2014-01-24 101 views
0

上運行應用程序,我在我的代碼中的錯誤,當我在下面網絡路徑找不到錯誤,而web服務器

給出的Web服務器運行此這表明network path was not found錯誤。 請幫我解決這個問題。

public class Connection 
{ 
    public SqlConnection con = new SqlConnection("server=173.192.96.130;Initial Catalog=hrmodule;Integrated Security=false;user=hrmodule1;[email protected]"); 

    SqlConnection getconnection() 
    { 
     return con; 
    } 
    public void openconn() 
    { 
     **con.Open();** the error occur on this line 

    } 
    public void closeconn() 
    { 
     con.Close(); 
    } 

    public DataTable GetData(string query) 
    { 
     SqlDataAdapter da = new SqlDataAdapter(query, getconnection()); 
     DataTable dt = new DataTable(); 
     da.Fill(dt); 
     return dt; 
    } 
    public void Storepro(string sp, string[] pn, string[] pt, string[] pv, int nos) 
    { 
     SqlCommand cmd = new SqlCommand(sp, con); 
     cmd.CommandType = CommandType.StoredProcedure; 
     for (int i = 0; i < nos; i++) 
     { 
      switch (pt[i]) 
      { 
       case "string": 
        cmd.Parameters.AddWithValue(pn[i], pv[i]); 
        break; 
       case "int": 
        cmd.Parameters.AddWithValue(pn[i], Convert.ToInt32(pv[i])); 
        break; 
       case "decimal": 
        cmd.Parameters.AddWithValue(pn[i], Convert.ToDecimal(pv[i])); 
        break; 
       case "DateTime": 
        cmd.Parameters.AddWithValue(pn[i], Convert.ToDateTime(pv[i])); 
        break; 
      } 

     } 
     con.Open(); 
     cmd.ExecuteNonQuery(); 
     con.Close(); 
    } 


} 
+6

顯示你的代碼..顯示您的error..Give我們更多的信息.​​. –

+0

你的代碼好友在哪裏? –

+0

http://stackoverflow.com/questions/how-to-ask –

回答

0

在web.config中你

<connectionStrings> 
    <add name="ProjectConnectionString" connectionString="Data Source=173.192.96.130;Initial Catalog=hrmodule;Integrated Security=false;user=hrmodule1;[email protected]"/> 
</connectionStrings> 

在C#頁面刪除

public SqlConnection con = new SqlConnection("server=173.192.96.130;Initial Catalog=hrmodule;Integrated Security=false;user=hrmodule1;[email protected]"); 

並添加

SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ProjectConnectionString"].ToString()); 
+0

在web配置文件中它應該是數據源代替服務器 – user3231286

+0

您可以將其更改爲方便。我只是給了提示。 –

+0

謝謝shreyas我的問題已經解決.. – user3231286

相關問題