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?
 
MlandaTConnect With a Mentor Commented:
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.