Monday, March 26, 2012

web.config problem

Hi

I am new to Visual Web Developer 2005 and have not been using it that long! I am in the process of creating a simple shopping cart facility for a web site that I am developing and have created all the pages and their relivant backend files to the specifications of the guide that I have been using. The probelm that I seem to be having is that I cannot get any of the pages to connect to the databases that I have created to store all the products and their relivant information. The guide that I have been using suggests that I should input the following code :

<

connectionStrings>

<

addname="ConnectionString"connectionString="Data

Source=localhost\SQLExpress;

Initial Catalog=Products;Integrated Security=True

"/>

</

connectionStrings>

straight after the <system.web> tag in the web.config file, but this does not seem to work and all I get is an error message saying:

unregognised configuration section system.web/connectionstrings.........web.config/line 14

Does anyone know what the correct codeing for the web.config file is to allow me to connect to the databases and allow my application to function correctly and also where this code should go in the web.config file. Any help would be greatly appreciated!

Cheers...............Jim

Hi

<appSettings>

<add key="ConnectionString"

value="Data

Source=localhost\SQLExpress;

Initial Catalog=Products;Integrated Security=True

"/>

</appSettings

>

Provide this piece of code after the <System.web> tag in ur config file ..

Hope it will resolve ur problem ..

Regards,
Sam


Hello,

Please look at this successful configuration file, and put your connection string before <system.web>, hope this helps.

<?xml version="1.0"?><configuration><connectionStrings><!-- This connection is inherited from the ASP.NET Quickstart Web.config file Uncomment this section to edit the sample locally<add name="Pubs" connectionString="Server=(local)\SQLExpress;Integrated Security=True;Database=pubs;Persist Security Info=True" providerName="System.Data.SqlClient"/><add name="Northwind" connectionString="Server=(local)\SQLExpress;Integrated Security=True;Database=Northwind;Persist Security Info=True" providerName="System.Data.SqlClient"/><add name="Contacts" connectionString="Server=(local)\SQLExpress;Integrated Security=True;Database=Contacts;Persist Security Info=True" providerName="System.Data.SqlClient"/> --><add name="NorthwindOLEDB" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|Northwind.mdb;" providerName="System.Data.OleDb"/><add name="ContactsDatabase" connectionString="Data Source=".\SQLEXPRESS";AttachDbFilename="|DataDirectory|Database.mdf";Integrated Security=True;User Instance=true;" providerName="System.Data.SqlClient"/></connectionStrings><system.web><pages styleSheetTheme="Default"/><caching><sqlCacheDependency enabled="true" pollTime="1000"><databases><add name="Pubs" connectionStringName="Pubs"/></databases></sqlCacheDependency></caching></system.web></configuration>

Excelent job, cheers Sam!!


Lovely job Jerome! cheers mate. Have marked as answered!

Hi Jerome

Sorry to bother you, but you answered one of my posts the other day concerning a web.config problem that I was having. I have subsiquently added the source code that you provided me with to my web.config file and made adjustments where necessary. When I now run rthe application in a browser to test it, the following error mesage is displayed:-

Server Error in '/ESSENCE SHOP' Application.

Cannot open database "Products" requested by the login. The login failed.
Login failed for user 'JAMES-JZYHKHV5P\james'.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.Data.SqlClient.SqlException: Cannot open database "Products" requested by the login. The login failed.
Login failed for user 'JAMES-JZYHKHV5P\james'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

I have not included the stack trace as this was rather a lot! I am not sure how to resolve this problem or even where the problem lies. If you have any further ideas, they would be greatly appreciated!!

Kind Regards........Jim


Higardnico1307,

What I give you is a special file for a special system. What I want to do is tell you how to configure your web.config. So you couldn't just copy and paste to your web.config because your system may have no SQL Server or that database or name and password.

Note every <add...> stands for a database, I think you want only one database, so you should just add one database with <add...> rather than five or more <add...> while my system have to use five databases so I have put five <add...>. What's more, you should change your name and password or connection type or the name of your database. If there is some more issue, please paste your web.config file for us to check it out.

Hope this helps.

0 comments:

Post a Comment