Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
It seems to me that a lot of people are getting similar problems to this, but I can't find a definitive answer, an actual explanation of how to correct it, just a lot of do's and don'ts !!!

I have created a small C# Windows Form Project using Visual Studio C# Express, SQL Server Express 2008 R2 and MS SQL Server Management Studio using this PC. It works fine as it is and I now want to test it on my laptop.

I clicked Project / Publish & followed the Wizard until it created a Folder called Application Files, a "ClickOnce Application Deployment Manifest" file and a Setup file all within my Published Projects Folder.

I then copied these 3 files to a USB and ran the Setup on my laptop. It installed a number of things and then came up with an MS .net Framework Error message saying "Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately. Cannot open database XXX requested by the login. The Login failed. The Login failed for user AAA"

Indeed, if I click Continue, the program starts to run and works until it tries to access the database, when I get the same message. Can somebody please explain clearly what I am doing wrong, or what I need to do to resolve this problem ?!?
Posted
Comments
Dave Kreskowiak 14-Mar-12 12:27pm    
Without seeing your connection string it's pretty difficult to say what's going on. Chances are good, though, that you have a misunderstanding of how SQL Server security works and you've got the connection string wrong because of it.
Gary Heath 14-Mar-12 12:32pm    
Well, Dave, it's very basic, but you'd be right about me not understanding many things, not just the SQL Server security !!!

@"Data Source=.\SQLEXPRESS;Initial Catalog=KAELC_DB;Integrated Security=True"
deepakaitr12345 17-Mar-12 9:29am    
Please Check the Remote services for the sql server and then try for it.

The most likely problem is that you don't have SQL server installed on any PC the target can reach, and the connection string you are trying to access your database with doesn't point at it anyway.

Try running a command prompt and typing "OSQL -L" and pressing ENTER. If it works, then it will show you all the instances you can reach from your PC. If it doesn't run at all, then SQL is not installed on that PC.

If you are only using a single user database (i.e. it doesn't share data with other users, you might want to switch to SQLite or SQLCE as they are much easier to install and manage than SQL server or MySql.
 
Share this answer
 
Comments
Gary Heath 14-Mar-12 13:02pm    
OK, well my first understanding is that when you Publish a Project, it includes what will be needed inside it somewhere as defined by the Prerequisites & that is why SQL Server Express & .Net Framework are installed onto the new PC (my laptop in this case, which has a newly built WinXP on it with no "extras") if they are not already there (I have .Net Framework 3.5 SP1, Microsoft .Net Framework 4 (x86 & x64), SQL Server 2008 Express, Windows Installer 3.1 & Windows Installer 4.5 checked as Prerequisites), is that not the case ?
OriginalGriff 14-Mar-12 13:04pm    
You should not include SQL Server in your installation. There are a couple of reasons:
0) You can only distribute SQL Server Express for copyright reasons - not SQL Server full version.
1) They may already have SQL Server installed on the network. If so, then they will presumably want to use that version.
2) If they do have SQL server installed and you start proliferating SQL server Express instances, you are going to annoy the heck out of the database administrator...
3) A single site installation of SQl Server is a lot more likely to be backed up than a number of scattered version under user control.
4) Sql server is quite complex for a "normal" user to install and administer - it is not a good idea!
5) It will destroy the primary advantage of using Sql Server over SqlCE or SQLite - multiuser access. If everyone installs their own copy of SQL server, then you will have multiple copies of your database, each used by a single person. This will cause some confusion, and (depending on how you wrote the original database) may take some considerable effort to combine into a single instance when the problem is realized.
OriginalGriff 14-Mar-12 13:04pm    
...And it doesn't mean you got the string right!
Gary Heath 14-Mar-12 13:11pm    
As for those commands on the Laptop, when I entered OSQL followed by anything I got the message "Error, no user selected. Try with -U or -E command". When I typed OSQL /? it suggested I use Sqlcmd. When I did so I got messages saying "HResult 0x2, Level 16, State 1. Named Pipes Provider: Could not open a connection to SQL Server [2]" ... and a lot more !!!

With regard to SQLite or SQLCE, this small project is part of my learning curve as I am supposed to be re-writing a big Basic program soon that will use C# & SQL Server, so I need to learn as much about it as I can !!!
Gary Heath 14-Mar-12 13:16pm    
Yes, thanks, I've seen these statements of yours in a number of places, but not until I had already tried installing my Project onto the laptop, so presumably the SQL Server Express option that is checked in my Prerequisites, should be unchecked for the future & SQL Server Express should be installed as a download on any PC that doesn't already have it on it, is that right ? Should I then uninstall anything on the laptop that relates to SQL Server & re-install from the MS Download ?
Sorry I never got back on this ... I gave up to be honest !!!

I'm now rewriting from scratch using VB.net & SQLCE (C# is just so confusing !) ... it seems smoother going so far, hopefully when I get to this point again I will understand a bit more !
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900