0

Most of my experience is with applications and I am having trouble working with a SQL query. The web page uses signalr to update clients with new info which will be controlled by a different process but what I am trying to implement is that new connected clients will not be at the same place as others already joined so it will update new clients with the correct info. I have this SQL Query ,

 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;

    }

Which I would like to return when a client connects

    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());
    }

while this works in a winapp , it breaks all of signalr on my page when run and does not return the result. I am probably doing something I am not supposed to , so I thought I would ask.

4
  • please post the error. Are you running it under IIS or from visual studio?
    – Ed Sykes
    Jul 25, 2012 at 14:06
  • There is no error, the content tries to refresh and succeeds but is always blank, normal strings work fine but so "hello world" would work, but not "hello world" + html is just empty. I have tried it both on IIS on the server and IIS express in VS2012.
    – user685590
    Jul 25, 2012 at 14:39
  • i am guessing you will need to encode the html before you send it
    – rpgmaker
    Jul 25, 2012 at 15:58
  • the html at the moment is a string of "ok" and won't need encoded , just trying to get the basics working.
    – user685590
    Jul 26, 2012 at 14:38

1 Answer 1

0

command.CommandText = "SELECT activepage FROM active";

instead of

command.CommandText = "SELECT TOP 1 activepage FROM active";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.