반응형
1. MySqlConnecter 설치
2. 참조 -> 참조 추가 -> MySql.Data.dll
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);
}
}
}
반응형
'Programming' 카테고리의 다른 글
.net 가상의 데이터 베이스에 자료를 입력해 데이터를 출력하기. (0) | 2010.06.08 |
---|---|
.net 에서 MySQL 데이터 읽어오기. (0) | 2010.06.08 |
Boxing 과 Unboxing (0) | 2010.04.30 |
C# 기초. (0) | 2010.04.30 |