471,066 Members | 1,164 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

Cannot Open local SQL Server Express Database


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

Oct 6 '06 #1
3 4431
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"co******@thewinesociety.com" wrote:
>
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();

Oct 6 '06 #2
Try to set Asynchronous Processing=true in the connection string.
Ann

<co******@thewinesociety.comwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
>
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();

Oct 7 '06 #3
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

Oct 9 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by wally | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.