using System;
using System.Data;
using System.Data.SqlClient;
namespace DBCONNECTION
{
class DbClass
{
public SqlConnection DbConnection(string str)
{
SqlConnection connection = new SqlConnection();
connection.ConnectionString = str;
connection.Open();
return connection;
}
}
class MainClass
{
public static void Main()
{
DbClass dc = new DbClass();
SqlConnection con1 = dc.DbConnection("server=localhost;database=pubs;uid=sa;pwd=#tlqkfdk");
SqlConnection con2 = dc.DbConnection("server=localhost;database=northwind;uid=sa;pwd=#tlqkfdk");
try
{
//con1.Open();
//con2.Open();
if(con1.State == ConnectionState.Open)
{
Console.WriteLine("첫번째 연결이 성공되었습니다.");
ViewDbState(con1);
}
if(con2.State == ConnectionState.Open)
{
Console.WriteLine("두번째 연결이 성공되었습니다.");
ViewDbState(con2);
}
}
catch(Exception E)
{
Console.WriteLine(E.Message);
}
finally
{
con1.Close();
con2.Close();
}
}
public static void ViewDbState(SqlConnection connection)
{
Console.WriteLine(connection.ServerVersion);
Console.WriteLine(connection.Database);
Console.WriteLine(connection.State.ToString());
}
}
}
2개의 연결 connection
|
2004.05.23 15:28:53
|
2004.05.23 15:28:53
|
353
|
Aiden
Total of Attached file
0.00 Bytes of 0 files
2012.07.22
2012.02.10
2008.12.27
2008.12.20
2008.04.09
2004.05.23
2003.10.21
2004.03.27
2003.06.30