C
collinsd
I am trying to connect to a database in SQL Server Express on my PC.
The SQLConnection open() method appears to work without generating any
exceptions however as soon as I try to do anything to the connection
such as BeginTransaction the program fails as it claims that the
connection is not open!
If I change the uid or password to garbage the SQLConnection Open
method fails so I know the database is being read.
The database is configured ofr windows and local password
authentication.
If anybody has any thoughts / ideas I would be very grateful to hear
them
If you need to know anthing else please ask.
Many Thanks....
Here is my code
string vSource, vSql;
SqlConnection vConnection;
SqlTransaction vTransaction;
SqlCommand vSqlCmd;
SqlDataReader vDataReader;
StringBuilder errorMessages = new StringBuilder();
vSource = "server = (local)\\SQLEXPRESS; " +
"uid = CSharpeUser; pwd = CSharpeUser1; " +
"database = DirectDebitAccounts";
using (vConnection = new SqlConnection(vSource))
try
{
vConnection.Open();
}
catch(SqlException ex)
{
MessageBox.Show("Failed"); //THIS MSG DOES NOT APPEAR
}
vTransaction = vConnection.BeginTransaction(); //FAILS AT
THIS POINT
vSqlCmd = new SqlCommand();
vSql = "Select ShareNum From DD_Accounts";
SqlCommand command = new SqlCommand(vSql, vConnection);
vDataReader = command.ExecuteReader();
while (vDataReader.Read())
{
MessageBox.Show((string)vDataReader[0]);
}
vTransaction.Commit();
vConnection.Close();
The SQLConnection open() method appears to work without generating any
exceptions however as soon as I try to do anything to the connection
such as BeginTransaction the program fails as it claims that the
connection is not open!
If I change the uid or password to garbage the SQLConnection Open
method fails so I know the database is being read.
The database is configured ofr windows and local password
authentication.
If anybody has any thoughts / ideas I would be very grateful to hear
them
If you need to know anthing else please ask.
Many Thanks....
Here is my code
string vSource, vSql;
SqlConnection vConnection;
SqlTransaction vTransaction;
SqlCommand vSqlCmd;
SqlDataReader vDataReader;
StringBuilder errorMessages = new StringBuilder();
vSource = "server = (local)\\SQLEXPRESS; " +
"uid = CSharpeUser; pwd = CSharpeUser1; " +
"database = DirectDebitAccounts";
using (vConnection = new SqlConnection(vSource))
try
{
vConnection.Open();
}
catch(SqlException ex)
{
MessageBox.Show("Failed"); //THIS MSG DOES NOT APPEAR
}
vTransaction = vConnection.BeginTransaction(); //FAILS AT
THIS POINT
vSqlCmd = new SqlCommand();
vSql = "Select ShareNum From DD_Accounts";
SqlCommand command = new SqlCommand(vSql, vConnection);
vDataReader = command.ExecuteReader();
while (vDataReader.Read())
{
MessageBox.Show((string)vDataReader[0]);
}
vTransaction.Commit();
vConnection.Close();