asp.net操纵Oracle存储过程

在bloginfo数据库中,利用用户名 system 密码 scy251147 选择超级管理员登陆  创建如下存储过程:

复制代码
 1 /*存储过程*/
 2 create or replace procedure sys.InsertInfo
 3 (
 4   TitleParams in nvarchar2,
 5   ContentParams in nvarchar2,
 6   Obj_Params out integer
 7 )
 8 
 9 is
10 begin
11       insert into testtable(ID,title,content)
12       values(seq_testtable_ids.nextval,TitleParams,ContentParams)
13 
14       return ID into Obj_Params;
15 
16 return;
17 exception
18      when no_data_found
19        then
20             null;
21      when others
22        then
23             raise;
24 end InsertInfo;
25 
26 
复制代码

然后就是asp.net端的操作代码:

复制代码
 1 using(OracleConnection conn = new OracleConnection("Data Source=BlogInfo;User ID=System;Password=scy251147"))
 2 {
 3     conn.Open();
 4     OracleCommand oracmd = new OracleCommand();
 5     oracmd.Connection = conn;
 6     DbParameter[] paras=new OracleParameter[3];
 7    
 8 
 9     paras[0] = new OracleParameter("TitleParams", OracleType.NVarChar,500);
10     paras[0].Value = "你好啊,哈哈哈哈哈";
11     paras[0].Direction = ParameterDirection.Input;
12 
13     paras[1] = new OracleParameter("ContentParams", OracleType.NVarChar,500);
14     paras[1].Value = "我今天很高兴,真的,希望大家都要高兴啊,哈哈哈哈";
15     paras[1].Direction = ParameterDirection.Input;
16 
17     paras[2] = new OracleParameter("Obj_Params",OracleType.Int32);
18     paras[2].Direction = ParameterDirection.Output;
19 
20  
21 
22     oracmd.Parameters.Add(paras[0]);
23     oracmd.Parameters.Add(paras[1]);
24     oracmd.Parameters.Add(paras[2]);
25 
26     oracmd.CommandText = "sys.INSERTINFO";
27 
28     oracmd.CommandType = CommandType.StoredProcedure;
29    
30     
31     oracmd.ExecuteNonQuery();
32     int i = Convert.ToInt32(paras[2].Value);
33     Response.Write(i.ToString());
34 }
35 
复制代码

从这里,我们看上去是一点问题都没有的,然后直接运行。
结果,一直提示“必须说明标识符“InsertInfo””(注意:我当时的语句是:oracmd.CommandText = "INSERTINFO";)
然后一直没找到结果,也没有发现程序中的错误,于是便想到了可能是授权的问题。
于是我退出超级管理员,然后利用用户名system 密码scy251147 选择Normal用户进行登陆,结果在利用
select * from testtable的时候,发现果真找不到这个表了,于是便利用select * from sys.testtable发现竟然显示
除了结果,于是便在语句前面加个sys.,一切正常了,返回了正确的数值。

猜想:可能是程序连接的时候,自动利用普通用户的权限进行登陆,而我的表是在超级管理员里面建立的,所以会看不到
只要在前面加上用户名称,就可以了,比如sys.testtabel。呵呵·~~~
小东西,看来里面的麻烦还不少。

原文地址:https://www.cnblogs.com/yezuhui/p/6836204.html