Link to home
Start Free TrialLog in
Avatar of Afzaal Khan
Afzaal Khan

asked on

Need to pass connection string through config

Hi Experts,

Need your help.

I am importing excel sheet to Sqldatabase by Sqlbulkcopy.

--------------------------------------------------------------

 using (SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection))
                {

                    // Destination table name.  Table name is sheet name minus any $
                    sqlBulk.DestinationTableName = sheetName.Replace("$", "");

                    foreach (var column in dt.Columns)
                    {

                        sqlBulk.ColumnMappings.Add(column.ToString(), column.ToString());
                    }

                    sqlBulk.WriteToServer(dt);

                }


                Oledbconn.Close();
            }

-----------------------------------------------------------------

I have to get connection string from config instead of hardcoded strConnection Can you help me  how I can pass here
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India 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
Avatar of Dmitry G
Please see the article from MSDN with proper explanations and examples:
Connection Strings and Configuration Files