2013年11月18日星期一
cheap thomas sabo charm carriers sale uk The ADO.Net Connection Object thomas sabo watches sale
Either in connected or cheap thomas sabo charm carriers sale uk disconnected mode, the first thing one needs to do is to connect to the database(s). This is accomplished in ADO.net by creating thomas sabo watches sale a connection object that points to the subject database.
The properties of the thomas sabo charm carriers uk connection object are:
Connection thomas sabo necklaces uk string
A string used to connect to the database.
Connection Timeout
thomas sabo watches uk online The number cheap thomas sabo rings sale uk of cheap thomas sabo chains sale seconds till a connection times out (Read Only)
Database
Returns the cheap thomas sabo rings uk database name thomas sabo watches uk as specified in connection string Cheap Thomas Sabo Australia (Read cheap thomas sabo earrings sale Only)
DataSource
Returns the source attribute thomas sabo rings uk as thomas sabo bracelets online specified in connection thomas sabo bracelets sale string thomas sabo pendant (Read Only)
ServerVersion
Returns version of connected server.
State
Returns state of current database thomas sabo charm carriers online in integers. Values thomas sabo pendants uk store can be Closed, Connecting, thomas sabo bracelets cheap Open, Thomas Sabo Australia sale Executing, Fetching, Broken
Provider
Returns the value of provider attribute thomas sabo charm carriers uk store as thomas sabo carriers sale specified in connection string (Read Only) (OleDb thomas sabo earrings cheap Only)
PacketSize
Returns thomas sabo chains uk size in thomas sabo chains uk store bytes of network packets (SQL Server only)
WorkstationID Identifies client, as specified in connection string (Read Only)
In the above table, the thomas sabo watches store only property that is NOT read only cheap thomas sabo charm carriers is the connection string. Thomas Sabo Australia cheap Some folks say that it is cheap thomas sabo bracelets the connection cheap thomas sabo chains sale uk string thomas sabo bracelets uk store that is the most discount thomas sabo earrings difficult aspect of ADO and thomas sabo chains store ADO.Net. If so, it thomas sabo necklaces cheap is an easily learned one. A typical connection thomas sabo bracelets uk string consists of 4 items:
The Provider, which specifies the name thomas sabo charm bracelet of the underlying OLEDB provider. Appropriate values are SQLOLEDB (for SQLServer), thomas sabo necklaces online Microsoft.Jet.OLEDB.4.0 thomas sabo charms uk (for Microsoft cheap thomas sabo charms sale uk Access) and MSDORA (for Oracle);
The thomas sabo carriers Data Source attribute, which shows the location thomas sabo charms online of cheap thomas sabo watches the database. It can be a path discount thomas sabo charm carriers on a network, or the IP thomas sabo carriers cheap address of a machine on the net;
The UserID and discount thomas sabo charms Password, which grant access permission to the database;
The Initial thomas sabo earrings uk Catalog, which thomas sabo charm earrings specifies the name of thomas sabo earrings sale the database in the data source.
Here are some common configurations:
For SQL Server –
Data Source=Jupiter;Initial Catalog=pubs;User Id=ElmerFudd;Password=wabbitt;
Server=Jupiter;Database=pubs;Trusted_Connection=True;Connection Timeout = 10
Data Source=200.192.23.155;Network Library=Wiley3301;Initial Catalog=pubs;User ID=ElmerFudd;Password=wabbitt;
C#:
using System.Data.SqlClient;
objqlConnection oSQLConn = new SqlConnection();oSQLConn.ConnectionString=connectstring;;oSQLConn.Open();
obj VB.NET:
Imports System.Data.SqlClient
Dim objSQLConn As SqlConnection thomas sabo charm rings = New SqlConnection()
objSQLConn.ConnectionString="connectstring"
objSQLConn.Open()
For Oracle:
Provider=OraOLEDB.Oracle;Data cheap thomas sabo earrings sale uk Source=mydatabase;User Id=ElmerFudd;Password=wabbitt;
Provider=OraOLEDB.Oracle;Data Source= mydatabase;OSAuthent=1;
C#:
using System.Data.OracleClient;
OracleConnection objOracleConn cheap thomas sabo bracelets uk = new OracleConnection();
objOracleConn.ConnectionString = Cheap Thomas Sabo sale my connectionstring;
objOracleConn.Open();
VB.NET:
Imports System.Data.OracleClient
Dim cheap thomas sabo chains objOracleConn As OracleConnection = New OracleConnection()
objOracleConn.ConnectionString = thomas sabo charm pendants myconnectionstring
objOracleConn.Open() thomas sabo bracelets uk online
For MS Access: thomas sabo chains
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\pathname\biblio.mdb;User Id=ElmerFudd;Password=wabbitt;
Notice that thomas sabo watches the last instruction in the code thomas sabo bracelets using the method ‘open()’. thomas sabo chains uk online After the connection cheap thomas sabo carriers has cheap thomas sabo watches sale been made, and thomas sabo rings uk online the data retrieved, thomas sabo rings uk store you need to close thomas sabo pendants uk the connection Cheap Thomas Sabo Australia online using the connection thomas sabo pendants cheap method ‘close()’. This should be done within an ‘if’ cheap thomas sabo earrings statement which Thomas Sabo Australia online first checks whether the connection is, discount thomas sabo bracelets in fact, open:
If (objConnection.state and ConnectionState.Open) 0 Then
objConnection.Close
End If
Note that the state property is ‘0’ if the connection is already thomas sabo charms uk online closed. Testing for a closed cheap thomas sabo charms uk connection is necessary cheap thomas sabo watches uk to prevent an error when you are thomas sabo pendants online invoking the ‘close’ method.
The connection objects methods are:
Open Opens connection
Close Closes thomas sabo chains cheap connection
BeginTransaction Begins database transaction
ChangeDatabase Changes the name thomas sabo chain of database connected cheap thomas sabo necklaces to
CreateCommand Creates a command object
GetOleDbSchemaTable Returns cheap thomas sabo pendants uk schema tables cheap thomas sabo pendants and discount thomas sabo watches associated restricted columns
ReleaseObjectPool Shared method which allows closing of cheap thomas sabo necklaces sale connection pool when Thomas Sabo Australia sale online last connection thomas sabo charms is closed
Exception Handling
All ADO connection thomas sabo carrier procedures should be protected thomas sabo pendants sale with a Try/Catch Block. When dealing thomas sabo carriers online with a connection to another server, this is especially important to let your users know that it was thomas sabo rings store the connection thomas sabo charm carriers sale that failed, rather than the application code.
Try
connSQLNorthwind.ConnectionString = _
"Server=Jupiter;Database=pubs;Trusted_Connection=True;Connection Timeout = 10"
Catch ExSQL cheap thomas sabo charm carriers sale As System.Data.SqlClient.SqlException
Dim strErrorMsg As String
Dim strerror As System.Data.SqlClient.SqlError
For Each strerror In cheap thomas sabo charms sale ExSQL.Errors
Select Case thomas sabo charm necklaces strerror.Number
Case 17
strErrorMsg = "Missing server"
Case 4060
strErrorMsg = "Missing database"
Case 18456
strErrorMsg = "Missing thomas sabo bracelets store user name or password"
Case Else
strErrorMsg = strerror.Message
End Select
MessageBox.Show(sErrorMsg, "SQL Server Error: " & thomas sabo charms cheap strerror.Number, MessageBoxButtons.OK thomas sabo earrings online MessageBoxIcon.Error)
Next
Catch ExcpInvOp As System.InvalidOperationException
MessageBox.Show("Close the connection first!", thomas sabo earrings _
"Invalid Operation MessageBoxButtons.OK, MessageBoxIcon.Error)
Catch thomas sabo necklaces uk store Excp As System.Exception ' generic exception handler
MessageBox.Show(Excp.Message, "Unexpected cheap thomas sabo charms Exception MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Resources
• Information on thomas sabo rings cheap ADO.Net Course
This resource provides information on ADO.Net course
• Article on cheap thomas sabo bracelets sale Microsoft .NET
This is a useful resource thomas sabo pendants that discusses .Net technology in discount thomas sabo rings detail.
订阅:
博文评论 (Atom)
没有评论:
发表评论