C # common database access solutions for access control

Source: Internet
Author: User

1. Common ASP + ACCESS database access failures Microsoft Jet Database Engine error '123' Solution
Open the filemonitor monitoring software, because it tracks too much information by default, resulting in an error like a haystack.
Here, you can first enable monitoring and then select the processes or directories you do not need to monitor.
Click Edit-> exclude process or edit-> exclude path in the menu to exclude the content that does not need to be monitored.
Then we can find that the generated information is greatly reduced.
Clear the output, start monitoring again, click the web page, and then stop monitoring. Soon I saw a message:

115 15:59:40 DLLHOST. EXE: 2804 create c: \ winnt \ temp \ jet5ea6. tmp Access Denied Cr \ iusr_cr

It can be seen that the C: \ winnt \ Temp directory is not open to the Cr \ iuser_cr account, as a result, temporary files cannot be created (it is strange that a temporary file needs to be generated when the account Cr \ user_cr accesses access ).

Find the Directory and set the permission. Then refresh the page and you will find it ready.
Of course, the directory name may not always be in this case, but the troubleshooting method is like this, which can be solved in general.

2, Access the database using C #

Recently, an Access database was used in this project, and no password was used for connection at first:

String connectionstring =   " Provider = Microsoft. Jet. oledb.4.0; Data Source = " ;
Connectionstring + =   @" C: \ data \ dB. MDB " ;
Oledbconnection con =   New Oledbconnection (connectionstring );
Con. open ();

Yes.

To ensure database security, users cannot directly open and edit the database, so they want to set a password for the ACCESS database: choose "Tools"> "security"> "set Database Password" from the menu. Then, the database cannot be accessed normally, adding the user ID and password fields to the connection string still does not work. At last, set the password in "tool"> "security"> "user and group account" to directly connect without changing the connection string. After this operation, you are prompted to enter a password when opening the file, which protects the ACCESS database.

Turn: http://rchen.cnblogs.com/archive/2005/09/19/239785.html

3. NTFS permission issues
When the disk partition is NTFS, data can only be read from the ACCESS database. Errors occur when you add, modify, or delete data. You need to set the access permission for the Access database, add the Asp.net account to the security of the folder attribute, and add the write and modify permissions for it. OK after the change

4,Access Database in Asp.netProgramSolution to the relative path in

Many of my friends are troubled by the relative path of the Access database in the. NET program, so every time a mobile program wants to modify web. config
Database path of the database connection string in. The Web. config statement is as follows:

<Deleetask>
<Add key = "oledbconnectionstring" value = "provider = Microsoft. Jet. oledb.4.0; Data

Source = E: \ WEB \ app_data \ data. mdb) "> </Add>
</Appsettings>

Write in the program as follows:

Myconn = new oledbconnection (system. configuration. configurationmanager. deleetpipeline ["oledbconnectionstring"]); // Note: The configurationsettings statements in vs2005 and vs2003 are different. Check the differences.

In this way, errors such as the following are often prompted during the program running:
'C: \ windows \ system32 \~ \ App_data \ data. mdb 'is not a valid path. Check whether the path name is correctly spelled and whether it is connected to the server where the file is stored. Data Source = ~ \ App_data \ data. MDB
Even if the absolute path is correct, you need to modify web. config when porting the program, which is troublesome.

Some web. config also uses server. mappath like ASP to retrieve the database path. However, Web. config does not know server. mappath, and this method does not work.

Later, by exploring and referring to other programs, we summarized the following methods to facilitate program migration without having to modify the ACCESS database path.

My web. config statement is as follows:

<Deleetask>
<Add key = "sqlconnstring" value = "provider = Microsoft. Jet. oledb.4.0; Data Source ="/>
<Add key = "dbpath" value = "~ /App_data/mydata. mdb "/>
</Appsettings>

In the program's data category class, I took "sqlconnstring" and "dbpath" and connected them to a string "conn_string_non_dtc"

Public static readonly string conn_string_non_dtc = system. configuration. configurationmanager. appsettings ["sqlconnstring"]. tostring () + system. web. httpcontext. current. server. mappath (configurationmanager. appsettings ["dbpath"]) + ";";
This is the way in vs2005.

I defined conn_string_non_dtc as static readonly for ease of use.
Okay, so you can transplant your program without worrying about the database path. It's suitable for a lazy person like me!

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.