我使用ADO.NET已经成功连上Sybase,但执行sql时报出标题所示异常
方法及调用代码如下:
//方法
public int ExecuteReader(string sql)
{
using (DbConnectionBuilder connBuilder = new DbConnectionBuilder(this._connectionString, this._providerName))
{
DbCommand cmd = connBuilder.Provider.CreateCommand();
cmd.CommandText = sql;
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = connBuilder.Connection;
DbDataReader read = cmd.ExecuteReader();
return read.FieldCount;
}
}
//调用
string sql = "select * from spt_mda";//失败
//string sql = "select 1 as RowNo";//成功
Response.Write("返回列数" + dbHelper.ExecuteReader(sql).ToString());
web.config配置:
<add name="SyBaseTest" connectionString=" Provider=sqloledb; Data Source=192.168.185.21; Initial Catalog=master; UID=sa; PWD=; " providerName="System.Data.OleDb"/>
帮忙看看,不胜感激
------解决方案--------------------
推荐使用换用ASE自带的ado.net连接方式.