Optimal Method for connecting ASP. NET to access, SQL Server, and Oracle Database in Web. config

Source: Internet
Author: User

. NET provides four Database Connection Methods:
System. Data. oledb. oledbconnection
System. Data. sqlclient. sqlconnection
System. Data. ODBC. odbcconnection
System. Data. oracleclient. oracleconnection
Access:
<Deleetask>
<Add key = "sqlconnstring" value = "provider = Microsoft. Jet. oledb.4.0; Password = admin;
User ID = admin; Data Source = "/>
<Add key = "dbpath" value = "~ /App_data/mydata. mdb "/>
</Appsettings>
Program Medium: connect "sqlconnstring" and "dbpath" to a 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"]) + ";";
Sqlclient:
Method (1): <connectionstrings>
<Add name = "sqlconnstring" connectionstring = "Data Source = localhost; Integrated Security = true; attachdbfilename = | datadirectory | pubs. MDF; user instance = true "providername =" system. data. sqlclient "/>
</Connectionstrings>
Method (2): <connectionstrings>
<Add name = "sqlconnstring" connectionstring = "Server = localhost;
Integrated Security = true; database = pubs; persist Security info = true"
Providername = "system. Data. sqlclient"/>
</Connectionstrings>
Program:
Using system. Data. sqlclient;
String connectionstring = configurationmanager. connectionstrings ["sqlconnstring"]. connectionstring;
Sqlserver common interface:
Method (1): <deleetask>
<Add key = "sqlconnection" value = "Server = (local); Integrated Security = sspi; database = pubs"/>
</Appsettings>
Method (2): <deleetask>
<Add key = "sqlconnection" value = "Data Source = localhost; Integrated Security = sspi; uid = sa; Pwd = passwords; initial catalog = pubs;"/>
</Appsettings>
Sqlserver exclusive interface (provided by sqlserver itself ):
<Deleetask>
<Add key = "sqlconnection" value = "provider = sqloledb; user id = sa; Password = Office; initial catalog = Office; server = localhost;"/>
</Appsettings>
Dedicated Oracle interfaces (provided by Oracle itself ):
Method (1): <deleetask>
<Add key = "oracleconnectionstring" value = "provider = oraoledb. oracle.1;
Persist Security info = false; Password = blah; user id = Greg; Data Source = 7d; "/>
<Deleetask>

Common Oracle interfaces:
Method (2 ):
<Deleetask>
<Add key = "oracleconnectionstring" value = "provider = msdaora; Password = tiger; user id = Scott; Data Source = 7d; persist Security info = false; integrated Security = yes "/>
<Deleetask>
Oracleclient:
<Deleetask>
<Add key = "connectionstring" value = "Data Source = testdb; user id = Scott; Password = tiger;"/> </appsettings>

Solution to connect to Oracle10g without installing the client

First, search for the following files on the machine where the Oracle server is installed,
OCI. dll
Ocijdbc10.dll
Ociw32.dll
Orannzsbb10.dll
Oraocci10.dll
Oraociei10.dll
Sqlnet. ora
Tnsnames. ora
Classes12.jar
Ojdbc14.jar

Make it into a compressed file and configure it for use by the target computer.

1. Extract oracleinstantclient.rar to a directory, such as D: \ oracleinstantclient

2. Configure the tnsnames. ora file of D: \ oracleinstantclient. You only need to modify the server address, service name, and port.

3. Configure the environment variable and add D: \ oracleinstantclient to the path variable.

4. Add the following key to the Registry

[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Session Manager \ environment]

"LD_LIBRARY_PATH" = "D: \ oracleinstantclient"

"Nls_lang" = "american_america.zhs16gbk"

"Tns_admin" = "D: \ oracleinstantclient"

5. For an ASP. NET application, you must assign the read and write permissions to the D: \ oracleinstantclient folder to the ASPNET user.

After the preceding settings, you can connect to the Oracle database server without installing the Oracle client.

You can also create an installation package from the decompressed files and manual processes to achieve automatic installation.

Note ):

1. IUSR _ computer name (Internet Guest Account) "and" iwaw _ computer name (start IIS process account) "are added to Oracle and fully controlled.
 
2. Find and install the Oracle directory, right-click and choose Properties> Security, and then:
(1) permission-> "Use the project displayed here that can be applied to sub-objects to replace all sub-objects"
(2) review-> "Use the project displayed here that can be applied to sub-objects to replace all sub-objects"
(3) Owner-> "Replace the owner of sub-containers and objects"
Method 1:

1. log on to Windows as administrator.

2. Find the Oracle installation directory, such as c: \ oracle.

Right-click the menu and select share and security for the directory (Click properties under win2000)

Click the "Security" tab and add an ASP. Net user to the group and user name. Click the "Asp.net" item in the list. In the permission list of the user, set the "read and run" selection box to "unselected", and then"

Use ";

Click "read and run" again, set it to the selected status, and then "Apply ".

3. Click "advanced" and select "whether Asp.net has" read and run "permission in the permission project and apply it to" this folder, and subfolders and files ". It is best to restart the machine and test whether the connection is normal.

.

4,Regsvr32 D: \ oracle \ 10.2.0 \ dB \ bin \ oraoledb10.dll

If method 1 still cannot be connected, refer to method 2.

Method 2:

Configure the Oracle connection using the method described earlier without installing the Oracle client, assign the read permission to the folder after the oracleinstantclient is decompressed to the ASPNET user, and remove the read permission of the ASPNET user on the Oracle main directory,

The ASP. NET application can also access the Oracle database. It does not conflict with the installed Oracle client.

Note: If the ASP. NET application and the Oracle database server are on the same machine, the solution is the same.

 

 

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.