2012-07-25 64 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活性」;