TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Rodney Johnson
NA
80
0
Connection String - SQL Conncetion through C#
Aug 3 2012 9:28 AM
I am receiving a SQLException in my code - a Timeout Expired exception. My code calls the connection string from a config file where the "connect time" is set to 180. The query takes about 41 seconds in SQL but I am getting the exception at 30 seconds.
------ C# code in the DBHelper Class ----------------------------
internal static DataTable dataCommand(string command)
{
SqlConnection sqlConn = ConnectToDatabase();
IDbTransaction transaction = sqlConn.BeginTransaction();
DataTable dt = new DataTable();
try
{
Database db = DatabaseFactory.CreateDatabase("MyDB");
SqlCommand com = new SqlCommand();
com.CommandText = command;
dt = db.ExecuteDataSet(com).Tables[0];
transaction.Commit();
}
catch
{
transaction.Rollback();
throw;
}
finally
{
if (sqlConn.State == ConnectionState.Open) sqlConn.Close();
}
return dt;
}
internal static SqlConnection ConnectToDatabase()
{
SqlConnection sqlConn = new SqlConnection();
sqlConn.ConnectionString = ConfigurationManager.ConnectionStrings["MyDB"].ToString();
sqlConn.Open();
return sqlConn;
}
------------------------- End of Code -----------------------------------
------------------------App Config connection string -----------------
<connectionStrings>
<add name="ProdProTrans042607"
connectionString="Data Source=indypro2\test3200;Initial Catalog=MyDB;
User ID = MyUserName;Password = MyPassword;connect timeout=180;"
providerName="System.Data.SqlClient" />
</connectionStrings >
------------- End of connection string -------------------------------------
When I break at the SQLConnection I can see the timeout is set to 180 but it continually fails.
Suggestions?
Rod
Reply
Answers (
3
)
Application.Startuppath in Windows Form with C#
Solve problem occured in connecting with SQL