failed to connect to Teradata server through C#

Connectivity

failed to connect to Teradata server through C#

I tried to connect to my Teradata server through C# (VS 2012 Express). But I kept getting error. I used MSSQL before. This is my first time using Teradata. I tried a few connectioin strings, but it did not help.

My OS is Windows 7 SP1 (64-bit). I have Teradata SQL Assistant (13.10.0.04) installed and connect to Teradata through ODBC.

my Teradata Client Provider version is v2.0.50727 (and referenced).

It seems I have problem in my connection string. Also, when to using TDConnection and when to use ODBCConnection?

Thank you in advance for your help.

 An unhandled exception of type 'System.ArgumentException' occurred in Teradata.Client.Provider.dllAdditional information: Invalid connection string.

Here are the detailed error:

A first chance exception of type 'System.ArgumentException' occurred in Teradata.Client.Provider.dll

An unhandled exception of type 'System.ArgumentException' occurred in Teradata.Client.Provider.dll

Additional information: Invalid connection string.

'ClassRoom.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

The program '[1460] 'ClassRoom.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).

my Code block list below:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Teradata.Client.Provider;

namespace ClassRoom

{

TdConnection cn = new TdConnection();

try

{

cn = new TdConnection("Driver=Teradata; Server=myTeradataServerIPAddress; Database=myDefaultDB; Uid=myID; Pwd =myPwd;");

cn.Open();

string strSQL = "SELECT name FROM Class.English WHERE StudentID='0100'";

TdCommand cmd = new TdCommand(strSQL);

string results = (String)cmd.ExecuteScalar();

Console.WriteLine("Teradata Database is {0}", results);

cmd.Dispose();

}

Tags (1)
3 REPLIES
Teradata Employee

Re: failed to connect to Teradata server through C#

You should use the TdConnectionStringBuilder class; set the Properties of the TdConnectionStringBuilder class and then retrieve the ConnectionString Property.

Also see

http://developer.teradata.com/doc/connectivity/tdnetdp/14.10/webhelp/DevelopingNetDataProviderforTer...

http://developer.teradata.com/doc/connectivity/tdnetdp/14.10/webhelp/webframe.html

http://developer.teradata.com/doc/connectivity/tdnetdp/14.10/webhelp/Teradata.Client.Provider~Terada...

Short answer; change the connection String to "Data Source=myTeradataServerIPAddress;User Id=X;Password=Y;"

Re: failed to connect to Teradata server through C#

Thank you NetFx for your reply. I tried your suggestion as following.  When code ran On cn.Open() I still got error (An unhandled exception of type 'Teradata.Client.Provider.TdException' occurred in Teradata.Client.Provider.dll)

I checked my local window, here is the error message: $exception{"[Teradata Database] [8017] The UserId, Password or Account is invalid."}   System.Exception {Teradata.Client.Provider.TdException}

My code block:

                TdConnectionStringBuilder builder=new TdConnectionStringBuilder();

                builder.Add("Data Source", "myserveripaddress");

                //builder.Add("Initial Catalog", "mydefaultdb");

                builder.Add("User ID", "myusername");

                builder.Add("Password", "myPw");

                TdConnection cn = new TdConnection(builder.ConnectionString);

                cn.Open();

I have tried quite few other connectionstring, and none of them seems work. Any other suggestion?

Teradata Employee

Re: failed to connect to Teradata server through C#

The properties of the TdConnectionStringBuilder class correspond to the connection string attributes. Therefore you can change your code to

builder.DataSource = "myDataSource";

builder.UserId = "x";

builder.Password = "Y";

The error message is very self explanatory; check your user-id and/or password.  The good news is that the Data Provider connected to the Teradata Database; so you are almost there.