Xin hướng dẫn cách đổi DBEngine.SystemDB property

  • Thread starter VAS
  • Ngày gửi
V

VAS

Guest
VAS có dòng code như sau:

DBEngine.SystemDB="Q:\ham\Companies_database\HAIDATA\DATA\Testimine\HAIEquitySecutiry.mdw"

Nhưng khi Debug.Print DBEngine.SystemDB thỉ nó vẫn là default setting

C:\Documents and Settings\jyrik\Application Data\Microsoft\Access\System.mdw"

Xin các bác chỉ giúp làm sao để VAS có thể đổi được DBEngine.SystemDB Setting ( = Code)

Xin cảm ơn rất nhiều.

Vas
 
Sửa lần cuối:
Khóa học Quản trị dòng tiền
V

VAS

Guest
Dear Bac Hai2Hai, Anh LeHongDuc,Anh DaoVietCuong,

Các anh vui lòng bỏ it thời gian giúp em giải quyết vấn đề trên nhé, mấy bữa nay em làm đủ trò rồi mà không được.

Xin chân thành cảm ơn.

VAS
 
hai2hai

hai2hai

VNUNI Makes a difference
29/4/04
2,032
125
63
50
Hà nội
vnuni.net
Hi VAS, vấn đề hay đấy nhưng có lẽ mình ko trả lời được rồi.
Mình chỉ trả lời được những gì liên quan đến VB thuần túy (có thể trả lời gần như bất kỳ vấn đề gì (99%) nếu có time và câu hỏi rõ ràng), chi tiết về quy trình lập trình, thiết kế phần mềm với ngôn ngữ UML sử dụng Rose hoặc các công cụ tương tự, đánh giá các công cụ, components trong lập trình (ActiveX and .NET,...), project mgt (cụ thể trong công việc phát triển phần mềm), bảo mật mang tính chất...chống CR ở mức B level, v.v...

Như từ khi có box Access mới thành lập thì mình đã nói là Access mình làm từ cái hồi chỉ có Access 2.0 (Office 4.3) và lâu quá rồi ko đụng đến nữa nên thực tình mình chỉ có thể nói về những cơ bản hoặc mang tính định hướng thôi. Còn những kỹ thuật liên quan trực tiếp đến Access thì mình thực sự ko đụng đến và ko muốn đụng đến nữa. Excel skills thì sorry, = nothing luôn.

Ở diễn đàn này có anh LeHongDuc, Paulstigel, DaoVietCuong, DoHung, TuanKTCDCN và 1 số bạn khác đang làm việc khá nhiều với Access. Hy vọng những members này có thể cùng chia sẻ KN với VAS.

P/S:
Mình chưa thử nhưng theo cách suy nghĩ của mình thì Access sẽ đọc cái SystemDB khi nó bắt đầu chạy (DBEngine bắt đầu start) từ Registry, INI hay từ đâu đó. Việc thay đổi DBEngine.SystemDB lúc runtime (bằng code) có thể là chỉ take effect được với 1 workspace mới thôi chứ current workspace chắc nó chưa take effect được.

Nếu làm theo hướng 1 thì có thể thì VAS thử tìm kiếm "C:\Documents and Settings\jyrik\Application Data\Microsoft\Access\System.mdw" và thay thế bằng đường dẫn riêng của bạn xem sao.

Còn nếu làm theo hướng 2 (thay SystemDB lúc runtime) thì có lẽ phải đọc thêm trong MSDN về bộ MS Office, chắc là có thôi.

Đó chỉ là suy nghĩ của mình thôi chứ thực sự mình ko muốn thử (mình thường hay nghĩ cách mà phần mềm sẽ làm gì trước khi tìm hiểu thực sự). Các members khác hãy thử giúp VAS trong vấn đề này hoặc ít nhất là đưa ra định hướng để VAS thử làm xem sao.
------------------------------------------------
30 giây cho google: Bạn có thể đọc bài này của Microsoft, có thể trả lời câu hỏi của bạn đấy:
http://support.microsoft.com/default.aspx?scid=KB;EN-US;q163002
http://emsindia.com/Hindi/H1/C669.html

In your Visual Basic code, indicate where system database, system.mdw, is located. You can either set the SystemDB property of the DBEngine object or set the IniPath property to the registry location of the system database. For example:
DbEngine.SystemDB="C:\MyApplication\system.mdw"

--> Đúng như mình phán đoán.

Tiếp theo:
'Set the location of the system database
DBEngine.SystemDB = "C:\Projects\Secured Database Article\system.mdw"

'Create a new workspace object
slUserName = Text1.Text
slPassword = Text2.Text
Set MyWorkspace = DBEngine.CreateWorkspace("New", _
slUserName, _
slPassword)

'Open the database
SecuredDB = "C:\Projects\Secured Database Article\Secure AccessDB.mdb"
Set db = DBEngine.Workspaces("New").OpenDatabase(SecuredDB)
'//.......

Nghĩa là sau khi Set the location of the system database thì phải Create a new workspace object thì khi đó new workspace mới take effect. Lại đúng như mình dự đoán. :)

More and more about this problem, please google: "DBEngine.SystemDB"

Chúc thành công!
 
Sửa lần cuối:
V

VAS

Guest
Dear Anh Hai2Hai,

Cảm ơn anh nhiều lắm,

Như em đã nói em đã thử nhiều cách kiếm được trên google nhưng ..Pó tay hic hic ( Cách của Anh em đã thử rồi.)

Hôm nay, em được biết nó không thể làm được trừ khi thay đổi DBEngine từ 1 access DB khác.

Lý do là khi mở một dự án Access thì CSDL làm việc sẽ thực hiện một kết nối thường trực dùng DAO thông qua đối tượng CurrentProject, và do đó, trong khi làm việc các thuộc tính liên quan đến system database sẽ trở thành chỉ đọc, vì thế không thể điều chỉnh thuộc tính SystemDB khi đã mở tập tin.

Trích từ http://www.microsoft.com/technet/prodtechnol/office/office2000/solution/part4/ch18.mspx?mfr=true

<<Note Once a database is opened, the Jet OLEDB:System Database and SystemDB properties become read-only. You can't change the path to the workgroup information file for the current database after it is opened. >>

Cám ơn anh một lần nữa vì sự nhiệt tình giúp đỡ.

VAS
 
Sửa lần cuối:
L

lehongduc

Trung cấp
29/3/05
131
1
18
64
VietNam
Nạp Database với các tùy chọn từ dòng lệnh

VAS nói:
VAS có dòng code như sau:

DBEngine.SystemDB="Q:\ham\Companies_database\HAIDATA\DATA\Testimine\HAIEquitySecutiry.mdw"

Nhưng khi Debug.Print DBEngine.SystemDB thỉ nó vẫn là default setting

C:\Documents and Settings\jyrik\Application Data\Microsoft\Access\System.mdw"

Xin các bác chỉ giúp làm sao để VAS có thể đổi được DBEngine.SystemDB Setting ( = Code)

Xin cảm ơn rất nhiều.

Vas

Bạn chịu khó đọc hướng dẫn dưới đây nhé, tôi bê nguyên xi của Bác Bill về đấy.
The following table lists the Microsoft Access command-line options.

Option Effect Applies to
-----------------------------------------------------------------
database Opens the specified Microsoft Access Access
database or Microsoft Access project. database or
Include a path if necessary. If you are Access
running Windows 95, the default path is project
your My Documents folder.

/excl Opens the specified Access database for Access
exclusive access. To open the database database
for shared access in a multiuser only
environment, omit this option.

/ro Opens the specified Access database or Access
Access project for read-only access. database or
Access
project

/user Starts Access using the specified user Access
user name name. database
only

/pwd Starts Access using the specified Access
password password. database
only

/profile Starts Access using the options in the Access
user specified user profile instead of the database or
profile standard Microsoft Windows registry Access
settings created when you installed project
Access. This replaces the /ini option
used in versions of Access earlier
than Access 97 to specify an
initialization file.

/compact Compacts and repairs the Access Access
target database, or compacts the Access project, database or
database or specified before the /compact option and Access
target then closes Access. If you omit a target project
Access file name following the /compact option,
project the file is compacted to the original
name and folder. To compact to a different
name, specify a target file. If you don't
include a path in target database or target
Access project, the target file is created
in your My Documents folder by default. In
an Access project, this option compacts
the Access project (.adp) file but not the
SQL Server database.

/repair Repairs the Access database specified Access
before the /repair option and then database
closesAccess. In Access 2000, compact only
and repair functionality is combined
under /compact. The /repair option is
supported for backward compatibility.

/convert Converts an Access database in an Access
target earlier version to an Access 2000 database
database database with a new name and then closes only
Access. Specify the source database
before using the /convert option.

/x macro Starts Access and runs the specified Access
macro. Another way to run a macro when database or
you open a database is to use an Access
AutoExec macro. project

/cmd Specifies that what follows on the Access
command line is the value that will be database or
returned by the Command function. This Access
option must be the last option on the project
command line. You can use a semicolon (;)
as an alternative to /cmd.

/nostartup Starts Access without displaying the Access
startup dialog box (the second dialog database or
box that you see when you start Access). Access
project

/wrkgrp Starts Access using the specified Access
workgroup workgroup information file. database
information only
file


Back to the top Back to the top
Notes
• To run a Visual Basic for Applications procedure when you open a database, use the RunCode action in the AutoExec macro or in the macro that you run by using the command-line option /x. You can also run a Visual Basic procedure when you open a database by creating a form with a Visual Basic procedure defined for its OnOpen event. Designate this form as the startup form by right-clicking the Database window, clicking Startup, and then entering that form in the Display Form/Page box.
• To specify a forward slash (/) or semicolon (;) on the command line, type the character twice. For example, to specify the password ;mjs/md on the command line, type ;;mjs//md following the /pwd command-line option.
• Examples:

You can type the following command in the Run dialog box to open an Access 2000 database in exclusive mode that runs the specified macro at the startup:
"C:\Program Files\Microsoft Office\Office\msaccess.exe" "C:\Program Files\Microsoft Office\Office\samples\northwind.mdb" /Excl /X Add Products
To open an Access 2002 database in exclusive mode that runs the specified macro at the startup, type the following command in the Run dialog box:
"C:\Program Files\Microsoft Office\Office10\msaccess.exe" "C:\Program Files\Microsoft Office\Office10\samples\northwind.mdb" /Excl /X Add Products
Similarly, if you want to open an Access 2003 database in exclusive mode that runs the specified macro at the startup, type the following command in the Run dialog box:
"C:\Program Files\Microsoft Office\Office11\msaccess.exe" "C:\Program Files\Microsoft Office\Office11\samples\northwind.mdb" /Excl /X Add ProductsThe following table lists the Microsoft Access command-line options.

Option Effect Applies to
-----------------------------------------------------------------
database Opens the specified Microsoft Access Access
database or Microsoft Access project. database or
Include a path if necessary. If you are Access
running Windows 95, the default path is project
your My Documents folder.

/excl Opens the specified Access database for Access
exclusive access. To open the database database
for shared access in a multiuser only
environment, omit this option.

/ro Opens the specified Access database or Access
Access project for read-only access. database or
Access
project

/user Starts Access using the specified user Access
user name name. database
only

/pwd Starts Access using the specified Access
password password. database
only

/profile Starts Access using the options in the Access
user specified user profile instead of the database or
profile standard Microsoft Windows registry Access
settings created when you installed project
Access. This replaces the /ini option
used in versions of Access earlier
than Access 97 to specify an
initialization file.

/compact Compacts and repairs the Access Access
target database, or compacts the Access project, database or
database or specified before the /compact option and Access
target then closes Access. If you omit a target project
Access file name following the /compact option,
project the file is compacted to the original
name and folder. To compact to a different
name, specify a target file. If you don't
include a path in target database or target
Access project, the target file is created
in your My Documents folder by default. In
an Access project, this option compacts
the Access project (.adp) file but not the
SQL Server database.

/repair Repairs the Access database specified Access
before the /repair option and then database
closesAccess. In Access 2000, compact only
and repair functionality is combined
under /compact. The /repair option is
supported for backward compatibility.

/convert Converts an Access database in an Access
target earlier version to an Access 2000 database
database database with a new name and then closes only
Access. Specify the source database
before using the /convert option.

/x macro Starts Access and runs the specified Access
macro. Another way to run a macro when database or
you open a database is to use an Access
AutoExec macro. project

/cmd Specifies that what follows on the Access
command line is the value that will be database or
returned by the Command function. This Access
option must be the last option on the project
command line. You can use a semicolon (;)
as an alternative to /cmd.

/nostartup Starts Access without displaying the Access
startup dialog box (the second dialog database or
box that you see when you start Access). Access
project

/wrkgrp Starts Access using the specified Access
workgroup workgroup information file. database
information only
file


Back to the top Back to the top
Notes
• To run a Visual Basic for Applications procedure when you open a database, use the RunCode action in the AutoExec macro or in the macro that you run by using the command-line option /x. You can also run a Visual Basic procedure when you open a database by creating a form with a Visual Basic procedure defined for its OnOpen event. Designate this form as the startup form by right-clicking the Database window, clicking Startup, and then entering that form in the Display Form/Page box.
• To specify a forward slash (/) or semicolon (;) on the command line, type the character twice. For example, to specify the password ;mjs/md on the command line, type ;;mjs//md following the /pwd command-line option.
• Examples:

You can type the following command in the Run dialog box to open an Access 2000 database in exclusive mode that runs the specified macro at the startup:
"C:\Program Files\Microsoft Office\Office\msaccess.exe" "C:\Program Files\Microsoft Office\Office\samples\northwind.mdb" /Excl /X Add Products
To open an Access 2002 database in exclusive mode that runs the specified macro at the startup, type the following command in the Run dialog box:
"C:\Program Files\Microsoft Office\Office10\msaccess.exe" "C:\Program Files\Microsoft Office\Office10\samples\northwind.mdb" /Excl /X Add Products
Similarly, if you want to open an Access 2003 database in exclusive mode that runs the specified macro at the startup, type the following command in the Run dialog box:
"C:\Program Files\Microsoft Office\Office11\msaccess.exe" "C:\Program Files\Microsoft Office\Office11\samples\northwind.mdb" /Excl /X Add Products
 

Xem nhiều

Webketoan Zalo OA