.Net Connection String with LDAP

Connectivity
Enthusiast

.Net Connection String with LDAP

Trying to connect through C# using an LDAP login:

 Teradata.Client.Provider.TdConnection con =

                    new Teradata.Client.Provider.TdConnection("Data Source=192.168.1.54;User ID=mw;Password=pwd;");

            con.Open();

Note I can log in with SQL Assistant with this server, user id, and password (so I think that's not the problem).

Also, if I use teradata auth, it this connection string works.

Error received (emphasis added is mine):

Teradata.Client.Provider.TdException was unhandled

  Message=[Teradata Database] [8017] The UserId, Password or Account is invalid.

  Source=Teradata Database

  ErrorCode=-2147467259

  TxRolledBack=true

  StackTrace:

       at Teradata.Client.Provider.WpMessageManager.CheckForError()

       at Teradata.Client.Provider.WpMessageManager.ProcessResponse()

       at Teradata.Client.Provider.WpLogonManager.Action()

       at Teradata.Client.Provider.WpSession.ManagerAction(WpMessageManager manager, Stopwatch watch, Int32 connectionTimeout)

       at Teradata.Client.Provider.WpSession.Open(Int32 connectionTimeout, String password)

       at Teradata.Client.Provider.Connection.Open(UtlConnectionString connectionString, UInt32 timeout)

       at Teradata.Client.Provider.ConnectionPool.CreateConnection(UInt32 timeout)

       at Teradata.Client.Provider.ConnectionPool.GetConnectionFromPool(Object owningObject)

       at Teradata.Client.Provider.ConnectionFactory.GetConnection(Object owningObject, UtlConnectionString connStr)

       at Teradata.Client.Provider.TdConnection.Open()

       at CodeEditor.CodeEditor.FileOpen_Click(Object sender, EventArgs e) in C:\BegASPNET\CodeEditor\CodeEditor\CodeEditor.cs:line 24

       at System.Windows.Forms.Control.OnClick(EventArgs e)

       at System.Windows.Forms.Button.OnClick(EventArgs e)

       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

       at System.Windows.Forms.Control.WndProc(Message& m)

       at System.Windows.Forms.ButtonBase.WndProc(Message& m)

       at System.Windows.Forms.Button.WndProc(Message& m)

       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)

       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)

       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)

       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)

       at System.Windows.Forms.Application.Run(Form mainForm)

       at CodeEditor.Program.Main() in C:\BegASPNET\CodeEditor\CodeEditor\Program.cs:line 18

       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)

       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)

       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

       at System.Threading.ThreadHelper.ThreadStart()

  InnerException:

4 REPLIES
Teradata Employee

Re: .Net Connection String with LDAP


Use TdConnectionStringBuilder class to build the Connection String; set TdConnectionStringBuilder.AuthenticationMechanism to LDAP. 


Data Source=192.168.1.54;User ID=mw;Password=pwd; Authentication Mechanism=LDAP;

Enthusiast

Re: .Net Connection String with LDAP

I got a working teradata ldap connection to work with c# with the following:

  •  // below has to be downloaded and "References"d in the project     
          using Teradata.Client.Provider;

                using (TdConnection cn = new TdConnection())

                {

                    TdConnectionStringBuilder conStrBuilder = new TdConnectionStringBuilder();

                    // i got the server from the ldap odbc description of the connection

                    conStrBuilder.DataSource = "tdserver.com";

                    conStrBuilder.Database = "mydb";

                    conStrBuilder.UserId = "myuid";

                    conStrBuilder.Password = "mypw";

                    conStrBuilder.AuthenticationMechanism = "LDAP";

                    Console.WriteLine("conn string was: " + conStrBuilder.ConnectionString);

                    cn.ConnectionString = conStrBuilder.ConnectionString; cn.Open();

                    TdCommand cmd = cn.CreateCommand();

                    cmd.CommandText = "select top 100 * from mydb.mytable";

                    TdDataReader reader = cmd.ExecuteReader();

                    Console.WriteLine("{0} records affected.", reader.RecordsAffected);

                    int currentRow = 1;

                    while (reader.Read())

                    {

                        for (int columnIndex = 0; columnIndex < reader.FieldCount; columnIndex++)

                        {

                            // this is pretty cool.  Does every field with it's name.

                            Console.WriteLine("Row [{0,4}] [{1,20}] = {2}",

                                    currentRow, reader.GetName(columnIndex),

                                    reader.GetValue(columnIndex));

                        }

                        Console.WriteLine();

                        currentRow++;

                    }

Enthusiast

Re: .Net Connection String with LDAP

The above was accomplished with the TD Plugin 14.1 and VS 2010.  Here is the connection string that worked (I obviously can't show our real organizational values) conn string was: Database=mydb;Authentication Mechanism=LDAP;User Id=myuid;Data

Source=tdserver.com;Password=mypw

Enthusiast

Re: .Net Connection String with LDAP

After you install the teradata client on your visual studio 2010 development machine, I "Reference", "Add", "Browse" Tab to this location to add the Teradata.Client.Provider using to the program:

C:\Program Files (x86)\Teradata\NET Data Provider for Teradata\13.11.00\bin\Teradata.Client.Provider.dll

Your's might be slightly different since most people are using the teradata 14.x client now.