473,320 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

C# - SQL Server Express Connection Problem

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

Jul 20 '07 #1
2 2610
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
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

Jul 20 '07 #2
dc
On 20 Jul, 11:46, Bram <b.fo...@gmail.comwrote:
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

Jul 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: amber | last post by:
Hello, I've just upgraded to VS.NET 2005 and SQL Server Express 2005. I converted my 2003 project into 2005. Now, when I try to run it, I get the error message: A first chance exception of...
0
by: Zorba.GR | last post by:
IBM DB2 Connect Enterprise Edition v8.2, other IBM DB2 (32 bit, 64 bit) (MULTiOS, Windows, Linux, Solaris), IBM iSoft Commerce Suite Server Enterprise v3.2.01, IBM Tivoli Storage Resource Manager...
14
by: Marcus | last post by:
I have a function that simply returns TRUE if it can connect to a particular Sql Server 2005 express, or FALSE if it cannot. I am getting some strange error codes returned when the computer that...
3
by: Arpan | last post by:
I recently installed SQL Server 2005 (Management Studio Express) along with SQL Server 2005 Express (Configuration Manager) in my Win2K Pro m/c & use IIS 5.0 to run ASPX projects. I could add my...
5
by: Glen Buell | last post by:
Hi all, I have a major problem with my ASP.NET website and it's SQL Server 2005 Express database, and I'm wondering if anyone could help me out with it. This site is on a webhost...
12
by: Light | last post by:
Hi all, I posted this question in the sqlserver.newusers group but I am not getting any response there so I am going to try it on the fine folks here:). I inherited some legacy ASP codes in my...
5
by: =?Utf-8?B?TWFya1NraQ==?= | last post by:
For about a month now, I have had trouble with Outlook Express. When logging in to Outlook Express, I get an error message stating that the connection to server has failed. My internet connection...
2
by: samadams_2006 | last post by:
Hello, I have a problem that I'm hoping someone will be able to help me resolve. 1) I have a C# Web Site in which I connect to the database: "Install Microsoft SQL Server 2005 Express...
4
by: James R. Davis | last post by:
.... due to failure in receiving user's application data path. Okay, this simply cannot be a problem unique to me and I assume there is a straight forward solution, but it escapes me. I have...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.