C++ Builder修改Access数据库密码
void __fastcall TForm1::Button1Click(TObject *Sender){ AnsiString f1= AccoutMe.mdb ; // 源库1 AnsiString psw1= 123456; // 密码 1,若设置错误也会报“意外错误” AnsiString f2= AccoutMe_new.mdb ; // 源库2 AnsiString psw2= abc; // 新 密码 2 bo
void __fastcall TForm1::Button1Click(TObject *Sender) { AnsiString f1= "AccoutMe.mdb "; // 源库1 AnsiString psw1= "123456"; // <strong>密码</strong>1,若设置错误也会报“意外错误” AnsiString f2= "AccoutMe_new.mdb "; // 源库2 AnsiString psw2= "abc"; // 新<strong>密码</strong>2 bool flg_Success = false; AnsiString dir = ExtractFilePath(Application-> ExeName); f1=dir+f1; //新<strong>数据库</strong>绝对路径 f2=dir+f2; if (FileExists( f2 ) ) //若目标文件已存在,先删除 DeleteFileA(f2); char Provider1[512] = { 0 }, Provider2[512] = { 0 }; sprintf(Provider1, "Provider=Microsoft.Jet.OLEDB.4.0;" "Data Source='%s';" "Jet OLEDB:Database Password='%s'" , f1, psw1 ); // sprintf(Provider2, // "Provider=Microsoft.Jet.4.0.OLE DB.Provider;" // "Data Source='%s';" // "Jet OLEDB:Database Password='%s'" // , f2, psw2 // ); // 注意提供正确的Provider写法,否则提示“意外错误” sprintf(Provider2, "Provider=Microsoft.Jet.OLEDB.4.0;" "Data Source='%s';" "Jet OLEDB:Database Password='%s'" , f2, psw2 ); Variant Adoobj = Variant::CreateObject( "JRO.JetEngine"); try { Adoobj.OleProcedure( "CompactDatabase", WideString(Provider1), WideString(Provider2) ); if (FileExists(f1)) DeleteFileA(f1); RenameFile(f2, f1); flg_Success = true; } __finally { Adoobj.Clear(); Adoobj = Unassigned; } ShowMessage( BoolToStr(flg_Success, true) ) ; }
这是OLE的方法,由于代码较简洁就不多写注释了。
原帖子见:http://topic.csdn.net/u/20120214/17/6bde8f44-3afb-4f8d-afc1-f971c879e3d9.html
特别感谢老妖!
PS:
OLE报错太不友好了。
不论是用独占方式打开ACCESS用SQL语句ALTER DATABASE PASSWORD "旧密码" "新密码",
还是用ADOQuery等控件,设置独占打开方式和 ADO 控件的SQL属性为"alter…………"修改ACCESS密码,都没有成功。
调试中ing...

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Golang and C each have their own advantages in performance competitions: 1) Golang is suitable for high concurrency and rapid development, and 2) C provides higher performance and fine-grained control. The selection should be based on project requirements and team technology stack.

In VS Code, you can run the program in the terminal through the following steps: Prepare the code and open the integrated terminal to ensure that the code directory is consistent with the terminal working directory. Select the run command according to the programming language (such as Python's python your_file_name.py) to check whether it runs successfully and resolve errors. Use the debugger to improve debugging efficiency.

Writing C in VS Code is not only feasible, but also efficient and elegant. The key is to install the excellent C/C extension, which provides functions such as code completion, syntax highlighting, and debugging. VS Code's debugging capabilities help you quickly locate bugs, while printf output is an old-fashioned but effective debugging method. In addition, when dynamic memory allocation, the return value should be checked and memory freed to prevent memory leaks, and debugging these issues is convenient in VS Code. Although VS Code cannot directly help with performance optimization, it provides a good development environment for easy analysis of code performance. Good programming habits, readability and maintainability are also crucial. Anyway, VS Code is

Golang is suitable for rapid development and concurrent programming, while C is more suitable for projects that require extreme performance and underlying control. 1) Golang's concurrency model simplifies concurrency programming through goroutine and channel. 2) C's template programming provides generic code and performance optimization. 3) Golang's garbage collection is convenient but may affect performance. C's memory management is complex but the control is fine.

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

The performance differences between Golang and C are mainly reflected in memory management, compilation optimization and runtime efficiency. 1) Golang's garbage collection mechanism is convenient but may affect performance, 2) C's manual memory management and compiler optimization are more efficient in recursive computing.

VS Code performs well on macOS and can improve development efficiency. The installation and configuration steps include: installing VS Code and configuring. Install language-specific extensions (such as ESLint for JavaScript). Install the extensions carefully to avoid excessive startup slowing down. Learn basic features such as Git integration, terminal and debugger. Set the appropriate theme and code fonts. Note potential issues: extended compatibility, file permissions, etc.
