You are currently viewing the BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
This removes the existing connection string defined in machine,config (which targets .\SqlExpress by default) and re-adds it, targeting your own database server.
Then when the application services such as membership and Profile need to access the database, they scan the connectionStrings setting, find localSqlServer and then target your own database at your local machine.
If I am only using Cassini as the .net server will it still interact with the local IIS
Nope. You either use IIS or Cassini.
Would it help if I reinstalled VS seeing as it is the only piece of software I have not reinstalled to get this code to work?
I don't think so. This sounds to me like a simple misconfiguration of database connection strings. Adding the code above should do the trick.
very strange thing. Literally started my laptop this morning, no changes what so ever, start VS, it cant find the SQL server. The data connections that I had set up before were still there but they were not connecting. Tried editing the connection and when it looks for the SQL server it doesnt find anything. All MSSQL services are running no problem, and I can login through management studio no problem.
This is really bizarre.
I tried running your code (as you said it will strip any existing connections and start a new one), I now have a new error message as follows:
Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'.
The error occurs on the same line of code where it is trying to call on the themes class.
I have run the SQL registration wizard in the framework64\v2.0.50727 folder and it has successfully added the aspnetdb database.
I have downloaded the reviewed appendix B that you mentioned, will go through it now and see if anything jumps out or fixes the issue, thought I would post my results in the meantime.
I have run through the revised appendix B that you linked to and found issues
1 - It suggests that configuring the permissions to the databases that I add the ASPNET user to the database logins. When I search for ASPNET user it does not find a matching user account on my local machine, anywhere.
2 - There was a similar snippet of code that he recommended to use which was similar to yours only he also specified the aspnetdb database (which i renamed wroxunitedmembership to avoid confusion).
Server Error in '/WroxUnited' Application.
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty.
Line 147: <roleManager>
Line 148: <providers>
Line 149: <add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=126.96.36.199, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
Line 150: <add name="AspNetWindowsTokenRoleProvider" applicationName="/" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=188.8.131.52, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
Line 151: </providers>
Source File: C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\machine.config Line: 149
Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3601
Not sure what to make of the error as the info relating to it is fairly minimal, if you have any further thoughts on the issues above let me know.
When I search for ASPNET user it does not find a matching user account on my local machine, anywhere.
What version of Windows are you using? ASPNET is specific to Windows XP.
which i renamed wroxunitedmembership to avoid confusion).
This adds to the confusion. LocalSqlServer is a reserved name that the application services look for. You need to name it LocalSqlServer or you need to tell the services configuration to look for a different name.For now, just rename it back (this is also what the error message is telling you).
I realised quite a few things here which will hopefully help anyone else having the same type of issue that I was having.
1 - I am running Vista 64bit ultimate OS, Visual Studio 2005 however is still running in 32bit mode. Because I am using cassini and not using local IIS to generate my web page, the process I was looking for to verify whether I should be registering .net configurations in the framework or framework64 folders was not clear. I discovered that the process for cassini was still running 32 bit process (process called: webdev.webserver.exe *32), so all changes I was previously doing in the framework64 folder were not having any effect as they should have been done in the 32 bit mode which is in the framework folder.
2 - I tried changing the machine.config files and all sorts of stuff to resolve the issue that the site was not finding my local sql server. When I ran your code that dropped the existing connection strings it was still giving an error that it could not find profile information, which is meant to be in the aspnetdb database. I realised that if that database was not specified in any connection strigs the profile information would never be found, so I ammended your code to the following which worked brilliantly:
By changing the LocalSqlServer reference to the aspnetdb database, and keeping the wroxunited connectionstring pointing to the wroxunited database it was then able to find both databases, and as a result the page loaded straight away with no errors what so ever.
This leads me to two final questions that I am still confused with as I spent a lot of time mucking around with these settings and they didnt have any effect.
1 - I tried runningthe asnet_regsql wizard from the framework and framework64 folders (ran them both). After running both of them it installed the aspnetdb datbase to the local sql server successfully, but it did not change the connectionstrings in the machine.config files. The machine.config files were stillpointing to the default ./SQLExpress source, even though the wizard completed successfully.
Why is it so? Why does it not change the default machine.config connectionstrings to reflect the correct source after running the wizard?
2 - Are there any other files apart from the machine.config files in each of the framework folders that contain connectionstring settings that either IIS or cassini will use for default database server connections?
I am going to try to change the machine.config files so that I dont need to keep using the code I mentioned above in order to connect to a database. I am going to be creating other databases of my own projects in the future and I would prefer to have the default settings for any new projects auto pointing to the proper database source (server).
Imar, thank you again for your patience and help with this issue, I truly am very appreciative.
*** Side note: I have changed the machine.config files with the proper connectionstring settings and the application runs with no errors. Feel free to ignore the second question above regarding any other files I need to change apart from the machine.config files.
I have changed the machine.config files with the proper connectionstring settings and the application runs with no errors.
I wouldn't recommend that solution as it applies to the enire system and could cause other issues with other applications later. If you can make it work this way, you should also be able to make it work by clearing the connectionStrings element in your own website using <clear /> and then readding the right connection strings...