성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Reordering on an Alpha processor ;...
[정성태] 공유 감사합니다. ^^ 참고로, WPF에서 WindowsF...
[Tom Lee] 답변 감사합니다. 나름의 해결책 연구해보고 여기에도 공유해봅니다...
[정성태] 아래의 글을 보면, MoveWindow 하면 될 듯한데요. ^^...
[Tom Lee] 안녕하세요 올려주신 글 참고하여 WPF 어플리케이션 안에 Uni...
[정성태] A graphical depiction of the steps ...
[정성태] 질문을 주셔서 출판사 측에 문의를 했습니다. 약 한 달 정도 후...
[Thorondor
] @정성태 개인 블로그인데도 거의 커뮤니티 급 인 것 같아요. 요...
[정성태] Roll A Lisp In C - Reading ; https...
[정성태] Java - How to use the Foreign Funct...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <div style='font-family: 맑은 고딕, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>Firebird 데이터베이스와 ADO.NET</div> <br /> 지난번 글에서 Firebird의 간편한 설치를 알아봤지요.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; width: 800px; background-color: #fbedbb; overflow-x: scroll; font-family: Consolas, Verdana;' > .NET 프로그래머에게도 유용한 Firebird 무료 데이터베이스 ; <a target='_tab' href='http://www.sysnet.pe.kr/2/0/1038'>http://www.sysnet.pe.kr/2/0/1038</a> </pre> <br /> 물론 설치만 알아봐서는 안되죠. ^^ ADO.NET으로 접근하는 방법을 살펴봐야겠습니다. 우선 Firebird용 ADO.NET Provider를 구해야 하는데 이는 firebird 공식 홈페이지에 공개되어 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; width: 800px; background-color: #fbedbb; overflow-x: scroll; font-family: Consolas, Verdana;' > DotNetFirebird - Using Firebird SQL in .NET. ; <a target='_tab' href='http://www.firebirdsql.org/dotnetfirebird/index.html'>http://www.firebirdsql.org/dotnetfirebird/index.html</a> Firebird - Browse /firebird-net-provider at SourceForge.net ; <a target='_tab' href='http://sourceforge.net/projects/firebird/files/firebird-net-provider/'>http://sourceforge.net/projects/firebird/files/firebird-net-provider/</a> </pre> <br /> 위의 폴더에 가면 현재(2011-05-16) 2.6.0 버전이 릴리스 된 것을 확인할 수 있고, MSI 파일과 ZIP 파일로 제공되는데 제 경우에는 NETProvider-2.6.0.zip 파일을 다운로드 받았습니다.<br /> <br /> ZIP 압축을 풀면 다음과 같이 4개의 파일을 볼 수 있습니다.<br /> <br /> <ul> <li><b style='COLOR: blue'>FirebirdSql.Data.FirebirdClient.dll</b></li> <li>FirebirdSql.Data.FirebirdClient.pdb</li> <li>FirebirdSql.Data.UnitTests.dll</li> <li>FirebirdSql.Data.UnitTests.dll.config</li> </ul> <br /> 척 보면 아시겠지만, 실제로 사용하는 파일은 단지 "FirebirdSql.Data.FirebirdClient.dll" 하나입니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 자, 이제 코드를 만들어봐야죠. ^^ 빈 프로젝트를 하나 만들고 "FirebirdSql.Data.FirebirdClient.dll" 파일을 참조 추가한 후, 지난번 글에서 실습했던 test.fdb로의 연결 및 CRUD 테스트를 해보겠습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; width: 800px; background-color: #fbedbb; overflow-x: scroll; font-family: Consolas, Verdana;' > DB 파일: c:\temp\test.fdb user 'SYSDBA' password 'masterkey' 테이블: TESTTABLE </pre> <br /> 코드는 그 자체가 설명서이니, 더 언급할 필요가 없겠죠. ^^<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; width: 800px; background-color: #fbedbb; overflow-x: scroll; font-family: Consolas, Verdana;' > static void Main(string[] args) { using (<b style='COLOR: blue'>FbConnection</b> fbConnection = new FbConnection(@"<b style='COLOR: blue'>DataSource=localhost;Port=3050;Database=c:\temp\test.fdb;User=SYSDBA;Password=masterkey</b>")) { fbConnection.Open(); // Create <b style='COLOR: blue'>FbCommand</b> insertCommand = new FbCommand(); insertCommand.Connection = fbConnection; insertCommand.CommandText = "<b style='COLOR: blue'>INSERT INTO TESTTABLE(NAME, DESCRIPTION) VALUES (@NAME, @DESCRIPTION)</b>"; insertCommand.Parameters.Add("@NAME", FbDbType.VarChar, 50); insertCommand.Parameters.Add("@DESCRIPTION", FbDbType.VarChar, 150); string nameValue = "Name" + Guid.NewGuid().ToString(); ; insertCommand.Parameters[0].Value = nameValue; insertCommand.Parameters[1].Value = nameValue + "_Description"; int affected = <b style='COLOR: blue'>insertCommand.ExecuteNonQuery</b>(); Console.WriteLine("# of affected row: " + affected); // Update FbCommand updateCommand = new FbCommand(); updateCommand.Connection = fbConnection; updateCommand.CommandText = "<b style='COLOR: blue'>UPDATE TESTTABLE SET DESCRIPTION=@DESCRIPTION WHERE NAME=@NAME</b>"; updateCommand.Parameters.Add("@NAME", FbDbType.VarChar, 50); updateCommand.Parameters.Add("@DESCRIPTION", FbDbType.VarChar, 150); updateCommand.Parameters[0].Value = nameValue; updateCommand.Parameters[1].Value = nameValue + "_Description2"; affected = updateCommand.ExecuteNonQuery(); Console.WriteLine("# of affected row: " + affected); // Select - ExecuteScalar FbCommand selectCommand = new FbCommand(); selectCommand.Connection = fbConnection; selectCommand.CommandText = "<b style='COLOR: blue'>SELECT count(*) FROM TESTTABLE</b>"; object result = <b style='COLOR: blue'>selectCommand.ExecuteScalar</b>(); Console.WriteLine("# of records: " + result); // Select - DataTable DataSet ds = new DataSet(); <b style='COLOR: blue'>FbDataAdapter da = new FbDataAdapter</b>("SELECT * FROM TESTTABLE", fbConnection); da.Fill(ds, "testTable"); DataTable dt = ds.Tables["testTable"]; foreach (DataRow dr in dt.Rows) { Console.WriteLine(string.Format("Name = {0}, Desc = {1}", dr["NAME"], dr["DESCRIPTION"])); } // Delete FbCommand deleteCommand = new FbCommand(); deleteCommand.Connection = fbConnection; deleteCommand.CommandText = "<b style='COLOR: blue'>DELETE FROM TESTTABLE WHERE NAME=@NAME</b>"; deleteCommand.Parameters.Add("@NAME", FbDbType.VarChar, 50); deleteCommand.Parameters[0].Value = nameValue; affected = deleteCommand.ExecuteNonQuery(); Console.WriteLine("# of affected row: " + affected); } } </pre> <br /> 보시는 바와 같이, SQL Server 접근과 거의 다르지 않습니다. 그 외에, 몇 가지 예제 코드는 다음의 사이트에서 볼 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; width: 800px; background-color: #fbedbb; overflow-x: scroll; font-family: Consolas, Verdana;' > DotNetFirebird - C# Sample Code ; <a target='_tab' href='http://www.firebirdsql.org/dotnetfirebird/sample-code.html'>http://www.firebirdsql.org/dotnetfirebird/sample-code.html</a> </pre> <br /> 참고로, FirebirdSql.Data.FirebirdClient 파일이 .NET 3.5용이라고는 하지만 .NET 4.0 응용 프로그램 및 x86/x64 모두 정상적으로 동작했습니다.<br /> <br /> (<a target='_tab' href='http://www.sysnet.pe.kr/bbs/DownloadAttachment.aspx?fid=592&boardid=331301885'>첨부한 파일은 위의 예제 코드</a>를 담고 있습니다.)<br /> <br /><br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
1046
(왼쪽의 숫자를 입력해야 합니다.)