C# Data link to another PC?
-
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? -
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? -
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?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]
-
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? -
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?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.
-
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?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