ASP.Net/ADO.net Database/Connection Compare — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 18:30, 26 мая 2010
Содержание
Compare connection: metadata (C#)
<source lang="csharp">
<%@ 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">
Properties from the MSDE Connection
From SqlConnection
ConnectionString: |
<asp:Label id="lblSqlConnectionString" runat="server">ConnectionString</asp:Label> |
ConnectionTimeout: |
<asp:Label id="lblSqlConnectionTimeout" runat="server">ConnectionTimeout</asp:Label> |
Database: |
<asp:Label id="lblSqlDatabase" runat="server">Database</asp:Label> |
DataSource: |
<asp:Label id="lblSqlDataSource" runat="server">DataSource</asp:Label> |
PacketSize: |
<asp:Label id="lblSqlPacketSize" runat="server">PacketSize</asp:Label> |
ServerVersion: |
<asp:Label id="lblSqlServerVersion" runat="server">ServerVersion</asp:Label> |
State: |
<asp:Label id="lblSqlState" runat="server">State</asp:Label> |
WorkstationId: |
<asp:Label id="lblSqlWorkstationId" runat="server">WorkstationId</asp:Label> |
From OleDbConnection
ConnectionString: |
<asp:Label id="lblOleDbConnectionString" runat="server">ConnectionString</asp:Label> |
ConnectionTimeout: |
<asp:Label id="lblOleDbConnectionTimeout" runat="server">ConnectionTimeout</asp:Label> |
Database: |
<asp:Label id="lblOleDbDatabase" runat="server">Database</asp:Label> |
DataSource: |
<asp:Label id="lblOleDbDataSource" runat="server">DataSource</asp:Label> |
Provider: |
<asp:Label id="lblOleDbProvider" runat="server">Provider</asp:Label> |
ServerVersion: |
<asp:Label id="lblOleDbServerVersion" runat="server">ServerVersion</asp:Label> |
State: |
<asp:Label id="lblOleDbState" runat="server">State</asp:Label> |
From OdbcConnection
ConnectionString: |
<asp:Label id="lblOdbcConnectionString" runat="server">ConnectionString</asp:Label> |
ConnectionTimeout: |
<asp:Label id="lblOdbcConnectionTimeout" runat="server">ConnectionTimeout</asp:Label> |
Database: |
<asp:Label id="lblOdbcDatabase" runat="server">Database</asp:Label> |
DataSource: |
<asp:Label id="lblOdbcDataSource" runat="server">DataSource</asp:Label> |
Driver: |
<asp:Label id="lblOdbcDriver" runat="server">Driver</asp:Label> |
ServerVersion: |
<asp:Label id="lblOdbcServerVersion" runat="server">ServerVersion</asp:Label> |
State: |
<asp:Label id="lblOdbcState" runat="server">State</asp:Label> |
</form>
</body> </html>
</source>