I wrote below code for my database connection but every time its catch part play.what is the problem?
public myDb()
{
canConnect = true;
sqlString = "Connection Timeout=5;Server=127.0.0.1;Database=ghanat;";
dbConnect = new SqlConnection(sqlString);
dbCmd = new SqlCommand();
dbCmd.Connection = dbConnect;
dbAdapter = new SqlDataAdapter(dbCmd);
try
{
dbConnect.Open();
MessageBox.Show("You connected", "Connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch
{
canConnect = false;
MessageBox.Show("Connection Error", "Connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
dbConnect.Close();
}
}
At the next step i have to send my sql string to database.
can you guide me or introduce me a clear brief Tutorial or an example project?
thanks alot.