Connecting to a Secured Access Database
Số trang: 3
Loại file: pdf
Dung lượng: 14.30 KB
Lượt xem: 1
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Connecting to a Secured Access Database Problem You want to connect to a Microsoft Access database that has been secured with user-level security and a workgroup file. Solution Use the Jet OLEDB:System Database attribute in the connection string to specify the path and filename of the workgroup information file or system database.
Nội dung trích xuất từ tài liệu:
Connecting to a Secured Access Database[ Team LiB ][ Team LiB ]Recipe 1.4 Connecting to a Secured Access DatabaseProblemYou want to connect to a Microsoft Access database that has been secured with user-levelsecurity and a workgroup file.SolutionUse the Jet OLEDB:System Database attribute in the connection string to specify the pathand filename of the workgroup information file or system database.The sample code contains a single event handler:Connect Button.Click Creates and opens a connection to a Microsoft Access database secured with user- level security and a workgroup file using the OLE DB .NET data provider. Information about the database is displayed from the properties of the OleDbConnection object.The C# code is shown in Example 1-4.Example 1-4. File: AccessSecureForm.cs// Namespaces, variables, and constantsusing System;using System.Configuration;using System.Text;using System.Data.OleDb;// . . .private void connectButton_Click(object sender, System.EventArgs e){ StringBuilder result = new StringBuilder( ); // Build the connection string with security information. String connectionString = ConfigurationSettings.AppSettings[MsAccess_ConnectString] + @Jet OLEDB:System database= +[ Team LiB ] ConfigurationSettings.AppSettings[MsAccess_SecureMdw_Filename] + ; + User ID= + userIdTextBox.Text + ; + Password= + passwordTextBox.Text + ; + Environment.NewLine + Environment.NewLine; result.Append(connectionString); // Create the connection. OleDbConnection conn = new OleDbConnection(connectionString); try { // Attempt to open the connection. conn.Open( ); result.Append( Connection State: + conn.State + Environment.NewLine + OLE DB Provider: + conn.Provider + Environment.NewLine + Server Version: + conn.ServerVersion + Environment.NewLine); conn.Close( ); result.Append(Connection State: + conn.State + Environment.NewLine); } catch(System.Data.OleDb.OleDbException ex) { result.Append(ERROR: + ex.Message); } resultTextBox.Text = result.ToString( );}DiscussionMicrosoft Access user-level security requires an additional file—the workgroupinformation or MDW file—in addition to the database or MDB file. This file contains theuser and group information for the secured database while the actual permissions arestored in the database file.When you connect to a secured Jet database, the user ID and password are validated[ Team LiB ]against the values in the MDW file. The permissions are obtained from the MDB file. Toconnect, the location of both the database file and the workgroup file must be supplied.The OLE DB provider for Microsoft Jet has several provider-specific connection stringattributes in addition to those defined by ADO.NET. To open a database secured byMicrosoft Access user-level security, use the Jet OLEDB:System Database attribute inthe connection string to specify the path and filename of the workgroup information fileor system database. This corresponds to the OLE DB propertyDBPROP_JETOLEDB_SYSDBPATH.[ Team LiB ]
Nội dung trích xuất từ tài liệu:
Connecting to a Secured Access Database[ Team LiB ][ Team LiB ]Recipe 1.4 Connecting to a Secured Access DatabaseProblemYou want to connect to a Microsoft Access database that has been secured with user-levelsecurity and a workgroup file.SolutionUse the Jet OLEDB:System Database attribute in the connection string to specify the pathand filename of the workgroup information file or system database.The sample code contains a single event handler:Connect Button.Click Creates and opens a connection to a Microsoft Access database secured with user- level security and a workgroup file using the OLE DB .NET data provider. Information about the database is displayed from the properties of the OleDbConnection object.The C# code is shown in Example 1-4.Example 1-4. File: AccessSecureForm.cs// Namespaces, variables, and constantsusing System;using System.Configuration;using System.Text;using System.Data.OleDb;// . . .private void connectButton_Click(object sender, System.EventArgs e){ StringBuilder result = new StringBuilder( ); // Build the connection string with security information. String connectionString = ConfigurationSettings.AppSettings[MsAccess_ConnectString] + @Jet OLEDB:System database= +[ Team LiB ] ConfigurationSettings.AppSettings[MsAccess_SecureMdw_Filename] + ; + User ID= + userIdTextBox.Text + ; + Password= + passwordTextBox.Text + ; + Environment.NewLine + Environment.NewLine; result.Append(connectionString); // Create the connection. OleDbConnection conn = new OleDbConnection(connectionString); try { // Attempt to open the connection. conn.Open( ); result.Append( Connection State: + conn.State + Environment.NewLine + OLE DB Provider: + conn.Provider + Environment.NewLine + Server Version: + conn.ServerVersion + Environment.NewLine); conn.Close( ); result.Append(Connection State: + conn.State + Environment.NewLine); } catch(System.Data.OleDb.OleDbException ex) { result.Append(ERROR: + ex.Message); } resultTextBox.Text = result.ToString( );}DiscussionMicrosoft Access user-level security requires an additional file—the workgroupinformation or MDW file—in addition to the database or MDB file. This file contains theuser and group information for the secured database while the actual permissions arestored in the database file.When you connect to a secured Jet database, the user ID and password are validated[ Team LiB ]against the values in the MDW file. The permissions are obtained from the MDB file. Toconnect, the location of both the database file and the workgroup file must be supplied.The OLE DB provider for Microsoft Jet has several provider-specific connection stringattributes in addition to those defined by ADO.NET. To open a database secured byMicrosoft Access user-level security, use the Jet OLEDB:System Database attribute inthe connection string to specify the path and filename of the workgroup information fileor system database. This corresponds to the OLE DB propertyDBPROP_JETOLEDB_SYSDBPATH.[ Team LiB ]
Tìm kiếm theo từ khóa liên quan:
công nghệ thông tin kỹ thuật lập trình Oreilly Ado Dot Net Cookbook Ebook-Lib Connecting to a Secured Access DatabaseGợi ý tài liệu liên quan:
-
52 trang 430 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 314 0 0 -
74 trang 299 0 0
-
96 trang 293 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 289 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 281 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 275 0 0 -
Tài liệu dạy học môn Tin học trong chương trình đào tạo trình độ cao đẳng
348 trang 269 1 0 -
Kỹ thuật lập trình trên Visual Basic 2005
148 trang 265 0 0 -
Tài liệu hướng dẫn sử dụng thư điện tử tài nguyên và môi trường
72 trang 265 0 0