2012-07-25 65 views
0

我的大部分经验是使用应用程序,而且我在使用SQL查询时遇到了问题。 网页使用信号发送器更新客户端,并用新的信息更新客户端,这些信息将由不同的进程控制,但是我试图实现的是新的客户端与其他客户端不会在同一地点,因此它将更新新的客户端正确的信息。我有这样的SQL查询,使用SignalR运行SQL查询

public string LoadCurrent() 
    { 
     SqlConnection con = new SqlConnection(); 

     SqlConnectionStringBuilder bldr = new SqlConnectionStringBuilder(); 
     bldr.DataSource = @"server\SQLEXPRESS"; 
     bldr.InitialCatalog = "Signalr_Example"; 
     bldr.UserID = "zip"; 
     bldr.Password = "zap"; 

     con.ConnectionString = bldr.ConnectionString; 

      con.Open(); 

      string currentPage = ""; 

      using (SqlCommand command = con.CreateCommand()) 
      { 
       command.CommandText = "SELECT TOP 1 activepage FROM active"; 

       con.Open(); 

       command.ExecuteNonQuery(); 

       SqlDataReader myReader = command.ExecuteReader(); 

       while (myReader.Read()) 
       { 
        int _currentpage = myReader.GetOrdinal("activepage"); 
        currentPage = myReader.GetString(_currentpage); 

       } 

      } 

     return currentPage; 

    } 

,我想,当一个客户端连接

public Task Connect() 
    { 
     string html = LoadCurrent(); 
     _connections.TryAdd(Context.ConnectionId, null); 
     //This runs firstview which populates a content div on new clients. 
     Clients[Context.ConnectionId].firstview(html); 
     return Clients.tally(_connections.Count.ToString()); 
    } 

,而这部作品在一个winapp返回,运行时,它打破了所有我的网页上signalr的和不返回结果。我可能在做我不应该做的事情,所以我想我会问。

+0

请发布错误。你是在IIS还是从Visual Studio运行它? – 2012-07-25 14:06:01

+0

没有错误,内容尝试刷新并成功,但始终为空,普通字符串正常工作,但“Hello World”可以工作,但不是“hello world”+ html只是空的。我已经在服务器上的IIS和VS2012中的IIS Express上尝试了它。 – user685590 2012-07-25 14:39:28

+0

我猜你需要在发送html之前先对html进行编码 – rpgmaker 2012-07-25 15:58:54

回答

0

command.CommandText =“SELECT activepage FROM active”;的

代替

command.CommandText = “SELECT TOP 1 activepage FROM活性”;