Link to home
Start Free TrialLog in
Avatar of woodje
woodjeFlag for United States of America

asked on

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

Avatar of Mlanda T
Mlanda T
Flag of South Africa image

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

Avatar of woodje

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of Mlanda T
Mlanda T
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial