.net과 mysql 연동하기 C#
2010.06.07 17:25 Edit
1. MySqlConnecter 설치
2. 참조 -> 참조 추가 -> MySql.Data.dll
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//DB접속 함수.
using MySql.Data;
using MySql.Data.MySqlClient;
using System.Data;
using System.Data.SqlClient;
namespace studyADONET
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// 데이터베이스 위치 정보 및 계정 정보를 저장하는 연결 문자
string strCon = "server=localhost;database=intra;uid=intra;pwd=intra";
// 데이터베이스와 연결을 담당하는 객체 생성
// 연결 문자열을 파라미터로 전달
MySqlConnection connection;
connection = new MySqlConnection();
connection.ConnectionString = strCon;
try
{
Response.Write("데이터베이스 연결중...");
connection.Open();
Response.Write("<br>데이터베이스 연결 성공");
Response.Write("<br>현재 데이터베이스 : " + connection.Database);
Response.Write("<br>연결 상태 : " + connection.State);
Response.Write("<br>데이터베이스 버전 : " + connection.ServerVersion);
}
catch (Exception E)
{
Response.Write("데이터베이스 연결 실패");
}
connection.Close();
Response.Write("<br>연결 상태 : " + connection.State);
}
}
}
- [2012/01/31] [MySQL] 관리자 root 의 password 재세팅 (58)
- [2012/01/31] [Linux] Admin Part II - FTP & DB 유저생성,권한설정 (64)
- [2011/09/15] mysql 5.5.14 버전 설치방법 및 설치후 발생 오류해결과정 (1959, 2)
- [2011/09/07] mysql replication 도중 slave 문제로 복구할때 master중지 없이 slave 복구하기 (1102, 4)
- [2011/05/20] mysql 5.5 설치 (2052)
- Tag :
- c# , asp.net , .net , mysql , mysqlconnector
