C# - SQL Server Express Connection Problem

D

dc

I have a baffling connection problem from my C# console app to a sql
server express database.

The console application opens the sql database using the following
code:-

vDataSource = "server = " + vgSqlServer + "; " +
"database = " + vgSqlServerDb + ";" +
"uid = XXX; pwd = XXX; ";

//create the connection
vSqlConnection = new SqlConnection(vDataSource);

try
{
vSqlConnection.Open();
}
catch (SqlException vSqlEx)
{
//connection failed
Console.Write("Connection Failed.\n\nError Number: " +
vSqlEx.Number + "\n\n" + vSqlEx.Message,
"Database Connection Failed");
}
catch (InvalidOperationException vEx)
{
Console.Write("Invalid Operation.\n\nError Number: " +
"\n\n" + vEx.Message,
"Database Connection Failed");
}

I have placed the application on a network drive ( just copying it not
using publisher) and from my PC the application works fine. However
when I try to run the application from any other machine on the same
network the connection fails with an MS "Tell us about this problem
message" - not even the catch seems to work. On looking at this
message the problem is an unhandled exception because the sqlclient
code cannot get permission to the database.

Both machines are using the same exe, and have similar set-ups.
Windows applications written in C# and accessing the same database
work perfectly on both machines.

I have tried connection using both SQl Server Login id's and windows
authentication with no effect

My machine has both SqlServer express manager and VS so my question
is - does anybody know of a reason why a console application will not
work on a PC where a windows application works correctly?

Sorry this is so long but I have tried to include all the details -
please ask if you need any further info.

Thanks you for your time....

DC
The Wine Society
 
B

Bram

I guess the exception is not caught because it is of a different type
than the ones in your catch clauses. My guess would be a
SecurityException. I'm not sure how to solve your problem, but maybe
inspecting the exception (either using a catch(SecurityException)
clause or a catch(Exception) clause could give your further pointers
to what's going wrong.

Regards
Bram
 
D

dc

I guess the exception is not caught because it is of a different type
than the ones in your catch clauses. My guess would be a
SecurityException. I'm not sure how to solve your problem, but maybe
inspecting the exception (either using a catch(SecurityException)
clause or a catch(Exception) clause could give your further pointers
to what's going wrong.

Regards
Bram

Having done that the message caught by exception is

Request for the permission of type
'System.Data.SqlClient.SqlClientPermission, S
ystem.Data, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' f
ailed.

Any thoughts welcome

DC
 

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