Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# Data link to another PC?

C# Data link to another PC?

Scheduled Pinned Locked Moved C#
questioncsharpdatabasesysadminsecurity
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    miss YY
    wrote on last edited by
    #1

    SqlConnection thisConnection = new SqlConnection( @"Server=(local);Integrated Security=True;" + "Database=northwind"); NOW the server is "local",but when i Install my Program on pc1,install DATABASE on pc2,how can i use date from pc2? i can not change server everytime,i think it can read from a comboBox?how can i do?

    C T R M H 5 Replies Last reply
    0
    • M miss YY

      SqlConnection thisConnection = new SqlConnection( @"Server=(local);Integrated Security=True;" + "Database=northwind"); NOW the server is "local",but when i Install my Program on pc1,install DATABASE on pc2,how can i use date from pc2? i can not change server everytime,i think it can read from a comboBox?how can i do?

      C Offline
      C Offline
      Calla
      wrote on last edited by
      #2

      You could build the connection string dynamically depending on which server you want to use. If this answer makes no sense to you, please elaborate your question :)

      1 Reply Last reply
      0
      • M miss YY

        SqlConnection thisConnection = new SqlConnection( @"Server=(local);Integrated Security=True;" + "Database=northwind"); NOW the server is "local",but when i Install my Program on pc1,install DATABASE on pc2,how can i use date from pc2? i can not change server everytime,i think it can read from a comboBox?how can i do?

        T Offline
        T Offline
        The Man from U N C L E
        wrote on last edited by
        #3

        if you use "pc2" instead of "(local)" your app will work what ever machine it is running on. Better to hold the connection string in a config file and provide a means to configure it within your app.

        If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

        1 Reply Last reply
        0
        • M miss YY

          SqlConnection thisConnection = new SqlConnection( @"Server=(local);Integrated Security=True;" + "Database=northwind"); NOW the server is "local",but when i Install my Program on pc1,install DATABASE on pc2,how can i use date from pc2? i can not change server everytime,i think it can read from a comboBox?how can i do?

          R Offline
          R Offline
          rag_Singh
          wrote on last edited by
          #4

          if you are running program on pc1 and installed database on PC2 then you shoud use connection string as below. SqlConnection thisConnection = new SqlConnection( "Server=pc2 IP or pc2 Name;Integrated Security=True; Database=northwind");

          1 Reply Last reply
          0
          • M miss YY

            SqlConnection thisConnection = new SqlConnection( @"Server=(local);Integrated Security=True;" + "Database=northwind"); NOW the server is "local",but when i Install my Program on pc1,install DATABASE on pc2,how can i use date from pc2? i can not change server everytime,i think it can read from a comboBox?how can i do?

            M Offline
            M Offline
            Md Marufuzzaman
            wrote on last edited by
            #5

            You can use DataLink to create connection from any workstation to database server...code snippets like

            MSDASC.DataLinks ObjDLink;
            ObjDLink= new MSDASC.DataLinks();
            ObjPrompt = ObjDLink.PromptNew();
            strConnectioString = ObjPrompt.ToString();

            Thanks Md. Marufuzzaman


            Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.

            1 Reply Last reply
            0
            • M miss YY

              SqlConnection thisConnection = new SqlConnection( @"Server=(local);Integrated Security=True;" + "Database=northwind"); NOW the server is "local",but when i Install my Program on pc1,install DATABASE on pc2,how can i use date from pc2? i can not change server everytime,i think it can read from a comboBox?how can i do?

              H Offline
              H Offline
              hamed vojdani
              wrote on last edited by
              #6

              My offer ,else use MSDASC class now see what is my offer.. 1- Server side: Run Sql Server browser Service in your database server machine, then create Valid login for your database,set sql server authentication to Windows and SQL athentication 2- Application side: with a form like this: http://privateimage.com/images/9fq89vuk7uokjz8koz.jpg and with functions like below for buttons

                  private void btnSearch\_Click(object sender, EventArgs e)
                  {
                      SqlDataSourceEnumerator SqlEnumerator = SqlDataSourceEnumerator.Instance;
                      DataTable dt = new DataTable();
                      dt = SqlEnumerator.GetDataSources();
                      dataGridView1.DataSource = dt.DefaultView;
                  }
              
              
                  private void btnSave\_Click(object sender, EventArgs e)
                  {
                      if (dataGridView1.SelectedRows.Count != 0)
                      {
                          string ConString = "";
              
                          SqlConnectionStringBuilder builder =new SqlConnectionStringBuilder();
                          builder.ApplicationName = "MyApp";
                          builder.WorkstationID = Environment.MachineName;
                          builder.UserID = txtLoginName.Text.Trim();
                          builder.Password = txtPassword.Text.Trim());
                          builder.InitialCatalog="MyDBName";                
                          builder.DataSource = dataGridView1.SelectedRows\[0\].Cells\["ServerName"\].Value.ToString()+
                         "\\\\"+dataGridView1.SelectedRows\[0\].Cells\["InstanceName"\].Value.ToString();
                          
                          ConString = builder.ConnectionString;
                          
                      }
                     
                  }
              

              at the end your data link string is ConString variable, you can store it in encrypted file or registry. each time application start check stored connection, and if failed retry this form note: used namespace are: using System.Data.Sql; using System.Data.SqlClient; hope helps with ugly sample ;)

              modified on Friday, December 25, 2009 9:45 AM

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups