"The key 'Main.ConnectionString' does not exist"

Aglaia avatar
LLBLGen Pro Team
Posts: 535
Joined: 07-Sep-2003
# Posted on: 21-Aug-2007 14:18:46   

Question: I've downloaded the demo application and generated code using the SqlServer demo database 'Northwind'. I wrote a simple ASP.NET application using the code but when I try to run that application, it throws an exception with the following error: "The key 'Main.ConnectionString' does not exist in the appSettings configuration section." What caused this error?

Solution: The generated code is a class library and is used in another program. The executable which ultimately is using the generated code (asp.net application, winforms application or console application), can be equiped with a .config file (web.config or app.config). LLBLGen Pro automatically generates a file called App.Config. This file contains a tag called . When you are using ASP.NET, you should copy that tag including its contents to the web.config file of your ASP.NET application and place it directly inside the tags. Now, the ASP.NET application has a definition of the Main.ConnectionString key and value and the generated code can read that key now to connect to the database. When you use winforms or a console application you can use the complete app.config file generated by LLBLGen Pro by adding it to the .exe project.