ASP.Net/ADO.net Database/Connection Compare
Версия от 15:30, 26 мая 2010; (обсуждение)
Compare connection: metadata (C#)
<%@ Page Language="C#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<%@ import Namespace="System.Data.OleDb" %>
<%@ import Namespace="System.Data.Odbc" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
SqlConnection mySqlConnection = new SqlConnection("Data Source=whsql-v08.prod.mesa1.secureserver.net;Initial Catalog=DB_49907;User ID=nfexuser;Password="password";");
mySqlConnection.Open();
lblSqlConnectionString.Text = mySqlConnection.ConnectionString;
lblSqlConnectionTimeout.Text = Convert.ToString(mySqlConnection.ConnectionTimeout);
lblSqlDatabase.Text = mySqlConnection.Database;
lblSqlDataSource.Text = mySqlConnection.DataSource;
lblSqlPacketSize.Text = Convert.ToString(mySqlConnection.PacketSize);
lblSqlServerVersion.Text = mySqlConnection.ServerVersion;
lblSqlState.Text = Convert.ToString(mySqlConnection.State);
lblSqlWorkstationId.Text = mySqlConnection.WorkstationId;
// close the connection
mySqlConnection.Close();
// *******************
// * OleDbConnection *
// *******************
// create the object
OleDbConnection myOleDbConnection = new OleDbConnection("provider=sqloledb;server=(local)\\BAND;database=Books;uid=band;pwd=letmein;");
// open the connection
myOleDbConnection.Open();
// set the labels on the form
lblOleDbConnectionString.Text = myOleDbConnection.ConnectionString;
lblOleDbConnectionTimeout.Text = Convert.ToString(myOleDbConnection.ConnectionTimeout);
lblOleDbDatabase.Text = myOleDbConnection.Database;
lblOleDbDataSource.Text = myOleDbConnection.DataSource;
lblOleDbProvider.Text = myOleDbConnection.Provider;
lblOleDbServerVersion.Text = myOleDbConnection.ServerVersion;
lblOleDbState.Text = Convert.ToString(myOleDbConnection.State);
// close the connection
myOleDbConnection.Close();
// *******************
// * OdbcConnection *
// *******************
// create the object
OdbcConnection myOdbcConnection = new OdbcConnection("driver={SQL Server};server=(local)\\BAND;database=Books;uid=band;pwd=letmein;");
// open the connection
myOdbcConnection.Open();
// set the labels on the form
lblOdbcConnectionString.Text = myOdbcConnection.ConnectionString;
lblOdbcConnectionTimeout.Text = Convert.ToString(myOdbcConnection.ConnectionTimeout);
lblOdbcDatabase.Text = myOdbcConnection.Database;
lblOdbcDataSource.Text = myOdbcConnection.DataSource;
lblOdbcDriver.Text = myOdbcConnection.Driver;
lblOdbcServerVersion.Text = myOdbcConnection.ServerVersion;
lblOdbcState.Text = Convert.ToString(myOdbcConnection.State);
// close the connection
myOdbcConnection.Close();
}
</script>
<html>
<head>
</head>
<body style="FONT-FAMILY: arial">
<form runat="server">
<h1>Properties from the MSDE Connection
</h1>
<hr size="1" />
<p>
</p>
<h2>From SqlConnection
</h2>
<table>
<tbody>
<tr>
<td>
ConnectionString:
</td>
<td>
<asp:Label id="lblSqlConnectionString" runat="server">ConnectionString</asp:Label></td>
</tr>
<tr>
<td>
ConnectionTimeout:
</td>
<td>
<asp:Label id="lblSqlConnectionTimeout" runat="server">ConnectionTimeout</asp:Label></td>
</tr>
<tr>
<td>
Database:
</td>
<td>
<asp:Label id="lblSqlDatabase" runat="server">Database</asp:Label></td>
</tr>
<tr>
<td>
DataSource:
</td>
<td>
<asp:Label id="lblSqlDataSource" runat="server">DataSource</asp:Label></td>
</tr>
<tr>
<td>
PacketSize:
</td>
<td>
<asp:Label id="lblSqlPacketSize" runat="server">PacketSize</asp:Label></td>
</tr>
<tr>
<td>
ServerVersion:
</td>
<td>
<asp:Label id="lblSqlServerVersion" runat="server">ServerVersion</asp:Label></td>
</tr>
<tr>
<td>
State:
</td>
<td>
<asp:Label id="lblSqlState" runat="server">State</asp:Label></td>
</tr>
<tr>
<td>
WorkstationId:
</td>
<td>
<asp:Label id="lblSqlWorkstationId" runat="server">WorkstationId</asp:Label></td>
</tr>
</tbody>
</table>
<p>
</p>
<h2>From OleDbConnection
</h2>
<table>
<tbody>
<tr>
<td>
ConnectionString:
</td>
<td>
<asp:Label id="lblOleDbConnectionString" runat="server">ConnectionString</asp:Label></td>
</tr>
<tr>
<td>
ConnectionTimeout:
</td>
<td>
<asp:Label id="lblOleDbConnectionTimeout" runat="server">ConnectionTimeout</asp:Label></td>
</tr>
<tr>
<td>
Database:
</td>
<td>
<asp:Label id="lblOleDbDatabase" runat="server">Database</asp:Label></td>
</tr>
<tr>
<td>
DataSource:
</td>
<td>
<asp:Label id="lblOleDbDataSource" runat="server">DataSource</asp:Label></td>
</tr>
<tr>
<td>
Provider:
</td>
<td>
<asp:Label id="lblOleDbProvider" runat="server">Provider</asp:Label></td>
</tr>
<tr>
<td>
ServerVersion:
</td>
<td>
<asp:Label id="lblOleDbServerVersion" runat="server">ServerVersion</asp:Label></td>
</tr>
<tr>
<td>
State:
</td>
<td>
<asp:Label id="lblOleDbState" runat="server">State</asp:Label></td>
</tr>
</tbody>
</table>
<p>
</p>
<h2>From OdbcConnection
</h2>
<table>
<tbody>
<tr>
<td>
ConnectionString:
</td>
<td>
<asp:Label id="lblOdbcConnectionString" runat="server">ConnectionString</asp:Label></td>
</tr>
<tr>
<td>
ConnectionTimeout:
</td>
<td>
<asp:Label id="lblOdbcConnectionTimeout" runat="server">ConnectionTimeout</asp:Label></td>
</tr>
<tr>
<td>
Database:
</td>
<td>
<asp:Label id="lblOdbcDatabase" runat="server">Database</asp:Label></td>
</tr>
<tr>
<td>
DataSource:
</td>
<td>
<asp:Label id="lblOdbcDataSource" runat="server">DataSource</asp:Label></td>
</tr>
<tr>
<td>
Driver:
</td>
<td>
<asp:Label id="lblOdbcDriver" runat="server">Driver</asp:Label></td>
</tr>
<tr>
<td>
ServerVersion:
</td>
<td>
<asp:Label id="lblOdbcServerVersion" runat="server">ServerVersion</asp:Label></td>
</tr>
<tr>
<td>
State:
</td>
<td>
<asp:Label id="lblOdbcState" runat="server">State</asp:Label></td>
</tr>
</tbody>
</table>
<p>
</p>
</form>
</body>
</html>