各位大侠,如果要访问远程数据库,在C#中,Sql语句如何来写呢。请大家帮帮忙啊,谢谢。

解决方案 »

  1.   

    server=远程主机;database=数据库;uid=;pwd=
      

  2.   

    web.config文件:  <appSettings>
    <add key="ConnStr" value="server=远程主机;database=数据库;uid=用户名;pwd=密码"/>
      </appSettings>.cs文件连接数据库语句:SqlConnection sqlcon=new SqlConnection(GetConnString());public static string GetConnString()
    {
      return System.Configuration.ConfigurationSettings.AppSettings["ConnStr"];
    }
      

  3.   

    SQLServerConnection  Conn;
    Conn = new SQLServerConnection("server=远程主机IP;database=数据库;uid=usersa;pwd=sa");
    try
    {
    Conn.Open();
    }
    catch (SQLServerException ex)
    {
    // Connection failed
    Console.WriteLine(ex.Message);
    return;
    }