oracle学习笔记1--开张! .net连接oracle

来源:互联网 发布:儿童日本js蓝光眼镜 编辑:程序博客网 时间:2024/06/17 14:53

项目压的紧,啥都要学,这不就开始搞oracle了

之前曾经看过一本oracle10g的书,应该是对oracle10g有了一个比较充分的了解,也上手操作过oracle,什么建表空间啊,乱七八糟也会,不过让我用.net连接oracle10g却发现困难重重。

先讲讲我开始犯的错误
我用的是vs2003(没安装任何oracle的软件,包括客户端,这直接导致了我走入了一个误区),随便建了一个页面,写了一段很简单的code,的就是测试能不能连上。使用了System.Data.OracleClinet这个命名空间,无奈事实是残酷的,系统报错了,System.DllNotFoundException: 无法加载 DLL (oci.dll)。
我原来一直以为oracle10g是不需要客户端软件的,因此之前都没装,经过google和baidu,发现我这种想法是及其错误的,需要客户端软件。
经过一番努力,客户端到手了。
(ps:oracle提供了各种类型的客户端软件,包括号称轻量级的免安装的,详见:
http://blog.csdn.net/spirit0416/archive/2006/10/12/1332297.aspx)

之后要步入正题了(下面都会针对ODAC、ODT等来讲,而不会针对轻量级的客户端)
1.oracle10g的网络概述
在net manager中可以设置监听程序,命名方法,本地net服务和目录使用。最后一个目录使用没用过,暂且不说。
监听程序不需要配置监听程序,服务器端需要配置命名方法不是很重要,配置的话可以按照oracle的步骤一步一步来,配置完成后生成文件sqlnet.ora本地net服务配置是客户端的核心,简单来说,.net通过本地net服务名来连接数据库,里面需要注意的是主机名最好使用ip

2.在vs2003中测试
我装的是ODT,其中包括了Oracle Data Provider for .NET,打开vs后,就会发现多了些东西
在.net中可以using Oracle.DataAccess.Client
这里面提供了和System.Data.OracleClinet接口一样的数据库连接类,如OracleCommand等。
(ps:针对.NET Framework Data Provider for Oracle和Oracle Developer Tools for Visual Studio .NET我在网上见过两种说法:
(a)是framework1中自带的类只适用于oracle8以下的版本,这个也没有加以论证过,不过我觉得有可能,framework1.1能否支持oracle9i,framework2.0能不能支持oracle10g就不清楚了
(b)有人说.NET Framework Data Provider for Oracle中bug比较多,不是很稳定,Oracle Developer Tools for Visual Studio .NET中较为稳定,具体没有试过)

语句是肯定没问题的,很简单。同时在vs的服务器资源管理器中可以连接到oracle10g上,但是在编译之后确仍然出现了“无法加载 DLL (oci.dll)”错误,这就令我很困惑,为什么转了一圈又回到了这个错误之上?

网上的解决方法大体相似一个比较全解决方法如下
oracle的一个bug在9i种就存在这个问题,就是其它用户没有权限访问oracle软件。

解决办法:
1.  Log on to Windows as a user with Administrator privileges.

   2.  Launch Windows Explorer from the Start Menu and and navigate to the
       ORACLE_HOME folder.  This is typically the "Ora92" folder under the
       "Oracle" folder (i.e. D:/Oracle/Ora92) in Oracle9iR2 or "Client_1"
       folder under the "Oracle/product/10.1.0" folder (i.e. D:/Oracle/product
       /10.1.0/Client_1) in Oracle10gR1.

   3.  Right-click on the ORACLE_HOME folder and choose the "Properties" option
       from the drop down list.  A "Properties" window should appear.

   4.  Click on the "Security" tab of the "Properties" window.

       NOTE: If you are running Windows XP and do not have a "Security" tab
             please do the following:
 
             (a) Open "Folder Options" in your Control Panel.
             (b) Choose the "View" tab.
             (c) Under "Advanced Settings" uncheck the option "Use simple file
                 sharing (Recommended)".

             The "Security" tab should now be available.

   5.  Click on "Authenticated Users" item in the "Name" list (on Windows XP
       the "Name" list is called "Group or user names").

   6.  Uncheck the "Read and Execute" box in the "Permissions" list under the
       "Allow" column (on Windows XP the "Permissions" list is called
       "Permissions for Authenticated Users").

   7.  Re-check the "Read and Execute" box under the "Allow" column (this is
       the box you just unchecked).

   8.  Click the "Advanced" button and in the "Permission Entries" list make
       sure you see the "Authenticated Users" listed there with:

           Permission = Read & Execute
             Apply To = This folder, subfolders and files

       If this is NOT the case, edit that line and make sure the "Apply onto"
       drop-down box is set to "This folder, subfolders and files".  This
       should already be set properly but it is important that you verify this.

   9.  Click the "Ok" button until you close out all of the security properties
       windows.  The cursor may present the hour glass for a few seconds as it
       applies the permissions you just changed to all subfolders and files.

  10.  Reboot your computer to assure that these changes have taken effect.

  11.  Re-execute the application and it should now work.

同时,也可以考虑提高aspnet这个用户在系统中的权限,比如提高到administrators

最后还要注意一个非常重要的问题,就是装了客户端之后一定要重启!!
我的客户端是装在fat32上的,装在ntfs上才需要前面的步骤这么做。

知识都是在不断的摸索中学习的,如何连接oracle10g折腾了我整整一天,但是在痛苦的挣扎中我也对oracle有了更深刻的认识,这是在书上无法学习到的。

问题:
在使用的过程中遇到了一个问题,希望能够解决
oracle10g提供了一个isqlplus的功能,我觉得没sqlplus好用,就下了一个instantclient-sqlplus-win32-10.1.0.5-

20060419.zip
装上了,也能够进sqlplus
服务器是192.168.0.3,数据库是eastern

192.168.0.101上netname我也配置了
-----------------------------------------------
TEST =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.3)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = eastern)
    )
  )
-----------------------------------------------
在net manager进行测试也能够连接的上
我使用tnsping test
-------------------------------------------
TNS Ping Utility for 32-bit Windows: Version 10.1.0.2.0 - Production on 12-10月-
2006 11:52:08

Copyright (c) 1997, 2003, Oracle.  All rights reserved.

已使用的参数文件:


已使用 TNSNAMES 适配器来解析别名
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)
(HOST = 192.168.0.3)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = eastern)))
OK (30 毫秒)
-------------------------------------------
但是在sqlplus上写sqlplus scott/tiger@test
的时候会出现ora12154:tns:could not resolve the connect identifier specified

不清楚是什么原因,csdn有几个热心人提出了他们的看法,不过都不见效,具体见
http://community.csdn.net/Expert/TopicView1.asp?id=5077252

在搞sqlplus过程中,对sqlplus和tnsping有了进一步的认识
详细信息见转贴
http://blog.csdn.net/spirit0416/archive/2006/10/12/1332285.aspx
http://blog.csdn.net/spirit0416/archive/2006/10/12/1332296.aspx 

原创粉丝点击