![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
Creating MySQL connection in C# <Solved>
hi, i'm using visual studio .net 2003 and i'm having trouble connecting my C# application to the MySQL database (testdb) on my computer using ODBC.
While creating the connection, it asks me for a DNS name or file or something so my question is how to create a DNS name for the MySQL database?i appreciate any help Last edited by OpenLoop; Jun 1st, 2005 at 5:55 PM. Reason: solved |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() |
just put in the ip address of the computer that you want it to connect to. Or if you have a domain name, you could get the domain host to put a entry into their control files for your db server. It's just as easy to just put the ip in though. If you are just doing some testing and have the mysql server setup on your development box, you can also just put in localhost as the DNS. However, if you plan on giving this program out, localhost won't work...simply cause when the other users (on different computers) would be looking at their boxes for the db server and your program would error out. Your best bet is the ip.
Suggestion, make a configure file, or dialog that lets you change the DNS settings for the mysql connection. that way if the location or ip of the mysql server ever changes, it will make your life alot easyer (as you will only have to change the DNS once instead of a whole bunch of times inside your code), and you won't have to re-compile your code.
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
|
|
#3 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
Thanks pizentios but putting the ip didn't work. I guess it's a bigger problem than i thought so i'll hit the books
![]() |
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() |
hey,
here's some code for you to look at: using System;
using System.Data;
using ByteFX.Data.MySqlClient;
public class ConnectToDatabase {
public static void Main(string [] args) {
string username = args[0];
string password = args[1];
string connectionString = string.Format("Server=localhost;" +
"Database=monodn;User ID={0};Password={1};", username, password);
MySqlConnection conn = null;
DataSet monodn = new DataSet("monodn");
try {
conn = new MySqlConnection(connectionString);
conn.Open();
MySqlDataAdapter adapter = new MySqlDataAdapter(
"select * from book", conn);
MySqlCommandBuilder cmdBuilder =
new MySqlCommandBuilder(adapter);
adapter.Fill(monodn);
conn.Close();
DataRow [] rows = monodn.Tables[0].Select("id = 1");
DataRow row = rows[0];
DateTime pubDate = (DateTime)row["pubdate"];
Console.WriteLine("original pubdate: {0}", pubDate);
row["pubdate"] = pubDate.AddDays(15);
Console.WriteLine("new pubdate: {0}",
monodn.Tables[0].Rows[0]["pubdate"]);
conn.Open();
adapter.Update(monodn);
conn.Close();
} catch (Exception e) {
Console.Error.WriteLine(e);
} finally {
if (conn != null && conn.State == ConnectionState.Open) {
conn.Close();
}
}
}
}Might help you figure out your problems?
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! Last edited by Pizentios; May 27th, 2005 at 10:22 AM. |
|
|
|
|
|
#5 |
|
Programming Guru
![]() ![]() ![]() |
Ahhh. I remember that code from the Element days
![]()
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#6 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
it worked
![]() thanks P. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|