C# .NET - Connecting to Remote Desktop and SQL server Database

Asked By Austine on 11-Feb-14 02:17 AM
Hi ,
   Please help with the code.
 i want to connect to Remote desktop using C# and also connect to a database in a remote desktop and pull information and display it in a gridview control.

Here is my code but it times out.

private void button1_Click(object sender, EventArgs e)
          rdp.Server = txtServer.Text;
          rdp.UserName = txtUserName.Text;

          IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx();
          secured.ClearTextPassword = txtPassword.Text;
          SqlConnection con=new SqlConnection(@"Server=blablabla;Database=blablabla;User Id=blablabla;Password=blablabla;");
          if (con.State == ConnectionState.Closed)

            DataTable dt = new DataTable();
            SqlDataAdapter sda = new SqlDataAdapter("select * from blablabla", con);
            dataGridView1.DataSource = dt;
        catch (Exception Ex)
          //MessageBox.Show("Error Connecting", "Error connecting to remote desktop " + txtServer.Text + " Error:  " + Ex.Message,MessageBoxButtons.OK, MessageBoxIcon.Error);

Please help to correct this code

Thanks a lot
Robbe Morris replied to Austine on 11-Feb-14 05:27 PM
SQL Server is not going to be able to hook into the connection you are making to the server via remote desktop.