Teradata database connection using web.config

Hello Expert,

I am using the .net data adapter for teradata. I can make my code work with defining the database connection in the code behind as seen in the code snipit. I have also created a connection string in my web.config file. I can't seem to get the coding right to use the web.config instead of coding in the page. Can you please help me?

Thanks,
Jeff
web.config setting
<add name="ndw_prd_allvm" connectionString="Provider=Teradata;DBCName=ipaddress;Database=datbasename;UID=userid;Pwd=password;"/>

Code Behind:
public static DataSet getTeradataData()
    {
        string _sql = "select * from ntl_prd_allvm.user_id_v where emp_id = '310332' and user_status_ind = 'a'";     
        TdConnection cn = new TdConnection();
        TdConnectionStringBuilder conStrBuilder = new TdConnectionStringBuilder();

        conStrBuilder.DataSource = "ipaddress";
        conStrBuilder.Database = "databasename";

        conStrBuilder.UserId = "userid"; conStrBuilder.Password = "password";
        cn.ConnectionString = conStrBuilder.ConnectionString;

        cn.Open();

        TdCommand cmd = cn.CreateCommand();
        cmd.CommandText = _sql;

        DataSet ds = new DataSet();


        TdDataAdapter da = new TdDataAdapter(cmd);
        da.Fill(ds);

        return (ds);
    }

Open in new window

woodjeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MlandaTCommented:
change:

        TdConnectionStringBuilder conStrBuilder = new TdConnectionStringBuilder();

        conStrBuilder.DataSource = "ipaddress";
        conStrBuilder.Database = "databasename";

        conStrBuilder.UserId = "userid"; conStrBuilder.Password = "password";
        cn.ConnectionString = conStrBuilder.ConnectionString;

Open in new window


to:
        cn.ConnectionString = ConfigurationManager.ConnectionStrings["ndw_prd_allvm"].ConnectionString;

Open in new window

0
woodjeAuthor Commented:
MlandaT,

I inserted your code and it passed the syntex verification. However I am getting an error when I try to run the app. The error is Invalid connection string. Parameter name: PROVIDER. I have relooked at my string but can't see any errors. Can you please review it and let me know what I have wrong. I have tried to verify to connectionstring.com as well.

Thanks,
Jeff
<add name="ndw_prd_allvm" connectionString="Provider=Teradata;DBCName=IPAddress;Database=DatabaseName;UID=UserID;Pwd=Password;"/>

Open in new window

0
MlandaTCommented:
Indeed, we are using Teradata .Net driver. It already knows it is Teradata :) The syntax should just be like:

Data Source=myServerAddress;User ID=myUsername;Password=myPassword;

Open in new window


Have a look: http://www.connectionstrings.com/teradata#p76
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Enterprise Software

From novice to tech pro — start learning today.