OdbcConnectionStringBuilder.Keys Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
ICollection Mendapatkan yang berisi kunci di OdbcConnectionStringBuilder.
public:
virtual property System::Collections::ICollection ^ Keys { System::Collections::ICollection ^ get(); };
public override System.Collections.ICollection Keys { get; }
member this.Keys : System.Collections.ICollection
Public Overrides ReadOnly Property Keys As ICollection
Nilai Properti
Yang ICollection berisi kunci dalam OdbcConnectionStringBuilder.
Contoh
Contoh aplikasi konsol berikut membuat baru OdbcConnectionStringBuilder. Kode mengulang melalui yang ICollection dikembalikan oleh properti yang Keys menampilkan pasangan kunci/nilai.
Catatan
Contoh ini mencakup kata sandi untuk menunjukkan cara OdbcConnectionStringBuilder kerja dengan string koneksi. Di aplikasi Anda, kami sarankan Anda menggunakan Autentikasi Windows. Jika Anda harus menggunakan kata sandi, jangan sertakan kata sandi yang dikodekan secara permanen dalam aplikasi Anda.
using System.Data.Odbc;
class Program
{
static void Main()
{
try
{
// Build an empty instance, just to see
// the contents of the keys.
DumpBuilderContents("");
// Create a SQL Server connection string.
DumpBuilderContents("Driver={SQL Server};Server=(local);Database=AdventureWorks;Uid=ab;Pwd=pass@word1");
// Create an Access connection string.
DumpBuilderContents(@"Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\info.mdb;Exclusive=1;Uid=admin;Pwd=pass@word1");
// Create an Oracle connection string.
DumpBuilderContents("Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=Admin;Pwd=pass@word1;");
// Create a Sybase connection string.
DumpBuilderContents("Driver={SYBASE ASE ODBC Driver};Srvr=SomeServer;Uid=admin;Pwd=pass@word1");
Console.WriteLine("Press any key to finish.");
Console.ReadLine();
}
catch (System.ArgumentException ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
private static void DumpBuilderContents(string connectString)
{
OdbcConnectionStringBuilder builder =
new OdbcConnectionStringBuilder(connectString);
Console.WriteLine("=================");
Console.WriteLine("Original connectString = " + connectString);
Console.WriteLine("builder.ConnectionString = " + builder.ConnectionString);
foreach (string key in builder.Keys)
{
Console.WriteLine(key + "=" + builder[key].ToString());
}
}
}
Imports System.Data.Odbc
Module Module1
Sub Main()
Try
' Build an empty instance, just to see
' the contents of the keys.
DumpBuilderContents("")
' Create a SQL Server connection string.
DumpBuilderContents("Driver={SQL Server};Server=(local);Database=AdventureWorks;Uid=ab;Pwd=pass@word1")
' Create an Access connection string.
DumpBuilderContents("Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\info.mdb;Exclusive=1;Uid=admin;Pwd=pass@word1")
' Create an Oracle connection string.
DumpBuilderContents("Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=Admin;Pwd=pass@word1;")
' Create a Sybase connection string.
DumpBuilderContents("Driver={SYBASE ASE ODBC Driver};Srvr=SomeServer;Uid=admin;Pwd=pass@word1")
Console.WriteLine("Press any key to finish.")
Console.ReadLine()
Catch ex As System.ArgumentException
Console.WriteLine("Error: " & ex.Message)
End Try
End Sub
Private Sub DumpBuilderContents(ByVal connectString As String)
Dim builder As New OdbcConnectionStringBuilder(connectString)
Console.WriteLine("=================")
Console.WriteLine("Original connectString = " & connectString)
Console.WriteLine("builder.ConnectionString = " & builder.ConnectionString)
For Each key As String In builder.Keys
Console.WriteLine(key & "=" & builder.Item(key).ToString)
Next
End Sub
End Module
Keterangan
Urutan nilai dalam ICollection urutan yang sama dengan nilai terkait dalam yang ICollection dikembalikan oleh Values properti .