读取局域网内数据服务器,提示ORA-01019错误

三生Omier 2012-06-10 05:04:07
做了一个读取局域网内数据库的webservice,webservice提供给外网的应用程序使用

运行之后,点击webservice网页中的方法连接,提示错误
<?xml version="1.0" encoding="utf-8" ?> 
<string xmlns="http://tempuri.org/"><bai_table><result>System.Data.OleDb.OleDbException: Error while trying to retrieve text for error ORA-01019 在 System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) 在 System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) 在 System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) 在 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) 在 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) 在 System.Data.OleDb.OleDbConnection.Open() 在 Service.getTaskInfo(DateTime startTime, DateTime endTime) 位置 d:\我的文档\Visual Studio 2008\WebSites\WebSite1\App_Code\Service.cs:行号 41</result></bai_table></string>


我的代码如下(很简单,只想测试一下webservice能否使用)
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;
using System.Data;
using System.Text;
using System.IO;
using System.Collections;
using System.Data.OleDb;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
public Service()
{

//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}

[WebMethod]
public String getTaskInfo(DateTime startTime, DateTime endTime)
{
//创建新的XML对象
XmlDocument doc = new XmlDocument();
//导入指定xml文件
doc.LoadXml("<bai_table>" + "</bai_table>");
//获取XML对象的根节点
XmlNode root = doc.DocumentElement;
//数据库连接
String ConnectionString = GetConnectString();
OleDbConnection connection = new OleDbConnection(ConnectionString);
String QueryString = "select pk_task,vbillcode,task_no,dbilldate,vagentid,pk_deptdoc from bai_table "
+ "where dr != 1 and dbilldate >= '" + startTime.ToString() + "' and dbilldate <= '" + endTime.ToString() + "'";
try
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = QueryString;
OleDbDataReader sr = command.ExecuteReader();
int rownum = 0;
while (sr.Read())
{
//每一次循环,先在根节点下面建立行节点,并且给行节点的行号赋值
XmlElement rowelement = doc.CreateElement("rowelement");
//行号赋值为rownum,在循环尾+1
rowelement.SetAttribute("rowNo", rownum.ToString());
//将行节点添加到根节点中
root.AppendChild(rowelement);

//给行节点添加每一个列节点并赋值
XmlElement elem0 = doc.CreateElement("pk_task");
rowelement.AppendChild(elem0);
String pk_task = sr["pk_task"].ToString();
elem0.InnerText = pk_task;

//....同上
XmlElement elem1 = doc.CreateElement("vbillcode");
rowelement.AppendChild(elem1);
String vbillcode = sr["vbillcode"].ToString();
elem1.InnerText = vbillcode;

//...同上
XmlElement elem2 = doc.CreateElement("task_no");
rowelement.AppendChild(elem2);
String task_no = sr["task_no"].ToString();
elem2.InnerText = task_no;

//...同上
XmlElement elem3 = doc.CreateElement("dbilldate");
rowelement.AppendChild(elem3);
String dbilldate = sr["dbilldate"].ToString();
elem3.InnerText = dbilldate;

//...同上
XmlElement elem4 = doc.CreateElement("vagentid");
rowelement.AppendChild(elem4);
String vagentid = sr["vagentid"].ToString();
elem4.InnerText = vagentid;

//...同上
XmlElement elem5 = doc.CreateElement("pk_deptdoc");
rowelement.AppendChild(elem5);
String pk_deptdoc = sr["pk_deptdoc"].ToString();
elem5.InnerText = pk_deptdoc;

//将行num+1
rownum++;
}
sr.Close();
}
catch (Exception ex)
{
XmlElement elem1 = doc.CreateElement("result");
elem1.InnerText = ex.ToString();
root.AppendChild(elem1);
}
doc.Save(@"D:/Web Services/bai_table.xml");
return doc.OuterXml;

}
public String GetConnectString()
{
return "provider=MSDAORA;host=192.168.168.198;data source=ORCL;user id=b;password=b";
//return "Data Source = (DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.168.88)"
// + "(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = orcl)));User Id=b;Password=b";
}
}


大家给帮忙看看吧,谢谢了
...全文
407 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
加油馒头 2012-06-12
  • 打赏
  • 举报
回复
现在本机测试一下 是否能够正常连上数据库

再在连接数据库的地方打个断点看看里面的值
  • 打赏
  • 举报
回复
把你的业务处理代码作为一个独立的类库,先单独测试(使用console或者桌面应用等都可以),不要从客户端去测试。特别是,web service向客户端隐藏了异常机制,难以调试。
三生Omier 2012-06-10
  • 打赏
  • 举报
回复
没有人回答么
三生Omier 2012-06-10
  • 打赏
  • 举报
回复
是不是连接串写的有问题呢

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧