Cannot Open local SQL Server Express Database

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();
 
G

Guest

At first blush, I don't see anything wrong with your code. However, wrapping
the call in a try/ catch block and displaying the exception message and the
InnerException message (if any) could certainly help.
Also, you might want to add a general Exception catch below the SqlException
catch just in case a thrown exception is *not* a SqlException.

Peter
 
C

collinsd

Hi Guys

Thanks for your suggestions.. Unfortunately adding the setting
Asynchronous Processing=true made no difference. I tried wrapping the
BeginTransaction cmd in a try/catch clause but the only messages
recieved stated that the the action failed as the database was not
open.

Could this be related to any settings (security or therwise) within SQL
Server Express? This is now my second day working with SSExpress so I
know very little about it (other than the contents of the wrox book
about it) so any other ideas would be wlecome
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top