我正在尝试使用.Net与以下代码连接Teradata。
但是当我执行它时,它会抛出一个错误,指出无效的连接字符串 在
Eclipse Oxygen 4.7.0
这里是完整的代码
TdDataAdapter adapter = new TdDataAdapter(cn.ConnectionString,cmd.CommandText);
我尝试使用using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Teradata.Client.Provider;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TdConnectionStringBuilder connectionStringBuilder = new TdConnectionStringBuilder();
connectionStringBuilder.DataSource = "URK";
connectionStringBuilder.Database = "DB";
connectionStringBuilder.UserId = "USERNAME";
connectionStringBuilder.Password = "PASSWORD";
connectionStringBuilder.AuthenticationMechanism = "LDAP";
TdConnection cn = new TdConnection();
cn.ConnectionString = connectionStringBuilder.ConnectionString;
cn.Open();
TdCommand cmd = new TdCommand("EXEC MACRONAME", cn);
TdDataReader reader = cmd.ExecuteReader();
TdDataAdapter adapter = new TdDataAdapter(cn.ConnectionString,cmd.CommandText);
DataSet ds = new DataSet();
adapter.Fill(ds);
myLabel.Text= ds.Tables[0].Rows[0]["event_id"].ToString();
cmd.Dispose();
cn.Close();
}
}
而不是上面使用的那个,但我仍然遇到了同样的错误。
答案 0 :(得分:1)
只需交换参数
TdDataAdapter adapter = new TdDataAdapter(cmd.CommandText, cn.ConnectionString);
根据TdDataAdapter
构造函数的签名
public TdDataAdapter(
string commandText,
string connectionString
)
请参阅docs