6 Replies - 1107 Views - Last Post: 02 June 2008 - 08:12 AM Rate Topic: -----

#1 RobinV  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 44
  • Joined: 21-May 08

Dymanic Database using? (MSSQL)

Post icon  Posted 21 May 2008 - 04:42 AM

How can I use a Microsoft SQL that is on a Random server in C#?
Since I want to be able to not connect to one database. But that I can point it to the Database that Ill use..
Since I might want to use the Database at IP xx.xx.xx.xx or I want to use it at yy.yy.yy.yy??

So, well can anyone tell me how to do this in VSC#2k5???

Or should I just write a DLL in C++ that will do this for me? ( ;) )

So, any advice? Tips? Tutorials? How tos? documents? Well you catch my drift.


Any help please =)

Thanks..

Robin

Is This A Good Question/Topic? 0
  • +

Replies To: Dymanic Database using? (MSSQL)

#2 zakary  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 427
  • Joined: 15-February 05

Re: Dymanic Database using? (MSSQL)

Posted 21 May 2008 - 05:17 AM

I am not 100% but baavgai will know and will correct me if I am wrong, but I believe in your connection string your server can be the ip of the machine your database is on,

string connectionString = "server=127.0.0.1;port=8000;user id=ab;" +
            "password= a!Pass113;database=MyDB";


Was This Post Helpful? 0
  • +
  • -

#3 RobinV  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 44
  • Joined: 21-May 08

Re: Dymanic Database using? (MSSQL)

Posted 21 May 2008 - 05:19 AM

Ah, and then I can use add what control to my forum?

Thanks already =)
Was This Post Helpful? 0
  • +
  • -

#4 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5882
  • View blog
  • Posts: 12,761
  • Joined: 16-October 07

Re: Dymanic Database using? (MSSQL)

Posted 21 May 2008 - 08:27 AM

You can connect to whatever you like. The connect string offered, or any you would use, would have to be given to a DataProvider that can handle the connection for you. e.g.

public DbConnection GetConnectionA() {
	return new SqlConnection(
		"Data Source=192.168.1.20;Initial Catalog=Foo;Integrated Security=True"
	);
}

public DbConnection GetConnectionB() {
	return new SqlConnection(
		"Data Source=192.168.1.22;Initial Catalog=Bar;Integrated Security=True"
	);
}

public bool TestConnection(DbConnection conn) {
	bool success = false;
	try {
		conn.Open();
		success = true;
	} catch (Exception ex) {
		Debug.WriteLine(ex.Message);
	} finally {
		conn.Close();
	}
	return success;
}

WriteLine("Connection A is " + ( TestConnection(GetConnectionA()) ? "Good" : "Bad" ) );
WriteLine("Connection B is " + ( TestConnection(GetConnectionB()) ? "Good" : "Bad" ) );



For a form, look into using DataSets.
Was This Post Helpful? 0
  • +
  • -

#5 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: Dymanic Database using? (MSSQL)

Posted 21 May 2008 - 10:08 AM

yes, you can use the IP address of the server where the database is located.
Was This Post Helpful? 0
  • +
  • -

#6 RobinV  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 44
  • Joined: 21-May 08

Re: Dymanic Database using? (MSSQL)

Posted 28 May 2008 - 05:17 AM

Ok, thanks a lot.
So I got this now:

string connectionString = "server=" + txtServIP.Text + ";port=" + numPort.Value.ToString() + ";user id=" + txtUname.Text + ";" + "password= " + txtPasswd.Text + ";database=" + txtDB.Text + "";
SqlConnection DatabaseConnection = new SqlConnection(connectionString);
DatabaseConnection.Open();

Now I THINK it connects.. (I aint sure)
How can I extract data now?
Since this is driving me Crazy :P ( I tryed Google )
Was This Post Helpful? 0
  • +
  • -

#7 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: Dymanic Database using? (MSSQL)

Posted 02 June 2008 - 08:12 AM

look up "ADO.Net" on Google.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1