SQL Database Connection String
example
try
{
using (SqlConnection sqlConn =
new SqlConnection(DatabaseConnectionString))
{
sqlConn.Open();
SqlCommand cmd =
sqlConn.CreateCommand();
cmd.CommandText = "select *
from somthing";
cmd.CommandType = CommandType.Text;
SqlDataReader dr =
cmd.ExecuteReader();
while
(dr.Read())
{
SelectedObject.Properties.Items.Add(dr[0].ToString());
}
dr.Close();
sqlConn.Close();
}
SelectedObject.Properties.NullText =
SelectObjectText;
Msg.Text = "";
if
(!IsDatabaseTextSet)
{
Msg.Text = SelectDatabaseMessageText;
Database.Text = SelectDatabaseText;
}
}
catch (Exception ex)
{
Database.Text = NoDatabaseFoundText;
Msg.Text = ex.Message;
Msg.Text = "ERROR: Failed to
connect to database server, please check your username and
password are correct.";
return;
}
finally
{
Application.UseWaitCursor =
oldUseWaitCursor;
}
|