ME-dia
ME-dia

Reputation: 289

Connecting To Local mySql Database

Currently I am connecting to an online mySql database. I would like to switch it to a mySql database on my local hard drive and am having problems with the syntax. Unlike the online one I have no UserID or Password. Any help is appreciated. Thank you.

(mysql_real_connect (conn,"urlock.db.5513143.hostedresource.com","urlock","passxxx","useridxxx",0,NULL,0) !=0);

tried this: (mysql_real_connect(conn,"c:\urlock.db","urlock","","",0,NULL,0) !=0);

didn't work.

Upvotes: 0

Views: 975

Answers (4)

ggenglish
ggenglish

Reputation: 1678

That second parameter needs to be a host which represents a network connection. It cannot be an absolute file reference like you might do with MS Access files. So, you need to install MySQL5.X on your system as a service. If you've done this, verify it by either looking for an open port of 3306 (default) via a 'netstat -an' command or simply look in your services for 'MySQL ....'.

If not, download it here: http://dev.mysql.com/downloads/mysql/

Once you get this you will be able to import the this database locally and be able to access it very similar to the online version. i.e. (mysql_real_connect(conn,"localhost","urlock","someuser","somepass",0,NULL,0) !=0);

Importing/exporting can be tricky but to point you in the right direction look into the mysqldump command.

Upvotes: 1

Tania Ang
Tania Ang

Reputation: 11624

  1. I believe the second parameter should be the host. If it is a local mySQL, the host is localhost.
  2. The default username is usually 'root'.

Try this:

(mysql_real_connect(conn,"localhost","urlock","","root",0,NULL,0) !=0);

Upvotes: 1

gkuan
gkuan

Reputation: 921

Most (if not all) installations of MySQL should have default accounts. There should at least be a root account. http://dev.mysql.com/doc/refman/5.1/en/default-privileges.html

Upvotes: 0

Haedrian
Haedrian

Reputation: 4328

You'll need a CONNECTIONSTRING

SqlConnection con = new SqlConnection(connectionString);

con.Open();

If you add your database in visual studio under Dataconnections, you can see the connection string under properties

ADDED:

If its an sqllite db, you need to use an SQLCeConneciton

private static string connectionString = @"Data Source=path/to/the/database/db.sdf"; private static SqlCeConnection con = new SqlCeConnection(connectionString);

Upvotes: -1

Related Questions