Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 135,924 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,607 people online right now. Registration is fast and FREE... Join Now!




Dymanic Database using? (MSSQL)

 
Reply to this topicStart new topic

Dymanic Database using? (MSSQL)

RobinV
21 May, 2008 - 03:42 AM
Post #1

New D.I.C Head
*

Joined: 21 May, 2008
Posts: 13


My Contributions
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? ( wink2.gif )

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


Any help please =)

Thanks..

Robin
User is offlineProfile CardPM
+Quote Post

zakary
RE: Dymanic Database Using? (MSSQL)
21 May, 2008 - 04:17 AM
Post #2

D.I.C Regular
Group Icon

Joined: 15 Feb, 2005
Posts: 404



Thanked: 6 times
Dream Kudos: 175
My Contributions
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,

csharp

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

User is online!Profile CardPM
+Quote Post

RobinV
RE: Dymanic Database Using? (MSSQL)
21 May, 2008 - 04:19 AM
Post #3

New D.I.C Head
*

Joined: 21 May, 2008
Posts: 13


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

Thanks already =)
User is offlineProfile CardPM
+Quote Post

baavgai
RE: Dymanic Database Using? (MSSQL)
21 May, 2008 - 07:27 AM
Post #4

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,015



Thanked: 105 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
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.

CODE

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.

User is offlineProfile CardPM
+Quote Post

eclipsed4utoo
RE: Dymanic Database Using? (MSSQL)
21 May, 2008 - 09:08 AM
Post #5

D.I.C Regular
Group Icon

Joined: 21 Mar, 2008
Posts: 349



Thanked: 19 times
Dream Kudos: 25
My Contributions
yes, you can use the IP address of the server where the database is located.
User is offlineProfile CardPM
+Quote Post

RobinV
RE: Dymanic Database Using? (MSSQL)
28 May, 2008 - 04:17 AM
Post #6

New D.I.C Head
*

Joined: 21 May, 2008
Posts: 13


My Contributions
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 tongue.gif ( I tryed Google )
User is offlineProfile CardPM
+Quote Post

eclipsed4utoo
RE: Dymanic Database Using? (MSSQL)
2 Jun, 2008 - 07:12 AM
Post #7

D.I.C Regular
Group Icon

Joined: 21 Mar, 2008
Posts: 349



Thanked: 19 times
Dream Kudos: 25
My Contributions
look up "ADO.Net" on Google.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 08:14AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month