Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 26th, 2005, 8:41 AM   #1
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
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
OpenLoop is offline   Reply With Quote
Old May 26th, 2005, 8:57 AM   #2
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
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!
Pizentios is offline   Reply With Quote
Old May 27th, 2005, 10:05 AM   #3
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
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
OpenLoop is offline   Reply With Quote
Old May 27th, 2005, 10:19 AM   #4
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
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.
Pizentios is offline   Reply With Quote
Old May 27th, 2005, 2:02 PM   #5
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old May 28th, 2005, 12:46 PM   #6
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
it worked
thanks P.
OpenLoop is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:11 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC