Xem mẫu

L p trình .NET và C#
Lecture 13:

SQL connection
TS ào Nam Anh
UTM, Khoa KH&CN

1

Resources
Các gi i pháp l p trình C#, Nguy n Ng c Bình Phương - Thái Thanh Phong
Allen Jones. C# Programmer's Cookbook. Microsoft Press, 2004
John Connell. Coding Techniques for Microsoft Visual Basic .NET. Microsoft
Press, 2002.
Harvey M. Deitel, Paul J. Deitel, & Tem R. Nieto. Visual Basic .NET How to
Program, Second Edition. Prentice Hall, 2002.
Jose Mojica. C# and VB .NET Conversion Pocket Reference. O'Reilly, 2002.
James Avery. Ten Must-Have Tools Every Developer Should Download Now.
MSDN Magazine, 2004.
Karl Moore. The Ultimate VB.NET and ASP.NET Code Book. Apress, 2003
Matthew MacDonald. Microsoft Visual Basic .NET Programmer's Cookbook.
Microsoft Press, 2003.
Mark Schmidt & Simon Robinson. Microsoft Visual C# .NET 2003 Developer's
Cookbook. Sams Publishing, 2003.
Dương Quang Thi n. L p trình Visual C# th nào? Nhà xu t b n T ng H p TP.
H Chí Minh, 2005.
Nguy n Ng c Bình Phương & Lê Tr n Nh t Quỳnh. Các gi i pháp l p trình
Visual Basic .NET. Nhà xu t b n Giao thông V n t i, 2006
www.msdn.microsoft.com, www.codeproject.com, www.msd2d.com,
www.developersdex.com, www.windowsforms.net, www.gotdotnet.com,
www.codeguru.com, www.developerfusion.com

2

Introduction
how to connect to a SQL Server

3

Making the Connection
using System.Data.SqlClient;
SqlConnection myConnection = new
SqlConnection("user id=username;" +
"password=password;server=serverurl;" +
"Trusted_Connection=yes;" +
"database=database; " + "connection
timeout=30");
4

User ID
The User ID is used when you are using SQL
Authentication. In my experience this is
ignored when using a Trusted_Connection, or
Windows Authentication. If the username is
associated with a password Password or
Pwd will be used
"user id=userid;"
5

nguon tai.lieu . vn