I was able to design and develop and nice website but I have difficulties deploying it in IIS 7. The site is a VS2010 website project that includes the ASPNETDB.MDF
database. In the project package/publish settings I selected the option Exclude files from App_Data folder and when importing the package into IIS7.5 the database is successfully created in the Users\AppData\... folder with a different name (XYZWebDB).
The site opens correctly and pages that have an asp:SQLDataSource element bind data correctly based on the connection string
name and SQL select command. Other pages that retrieve the connection string with C# simply hang and don’t do anything.
To get it
successfully imported it into IIS and without modifying any IIS options I removed the whole web.config section runAllManagedModulesForAllRequests. I decided to do this after reading that a lot of people have difficulties with this keyword and not finding any
clear cut answers, unless digging into IIS and the allow/deny options. I don’t want to get into IIS. I simply want to test the app and uploaded to the web!
Perhaps I am not doing things right. The above left me with the following questions:
Does the C# connection string look at a different config(?) file information compared to the asp:SQLDataSource element?
Where is this information stored?
Any help would be very much appreciated and many thanks in advance to all the people reading this.
Have a wonderful day…
Regards
Michael
PS The following connection strings were used:
The asp:SQLDataSource setting is:
<asp:SqlDataSource
ID="SqlDataSourceProduct" DataSourceMode="DataReader" ConnectionString="<%$ ConnectionStrings:ApplicationServices%>" SelectCommand="SELECT Product, AUDinclGST FROM tbl_product WHERE ProductID < 11" runat="server"></asp:SqlDataSource>
The C# get connection string is copied from MSDB Library:
--Michael--
Member
46 Points
21 Posts
Why do asp:SQLDataSource and C# connectionString point to two different configs?
Jul 29, 2012 07:30 AM|LINK
Hi there,
I was able to design and develop and nice website but I have difficulties deploying it in IIS 7. The site is a VS2010 website project that includes the ASPNETDB.MDF database. In the project package/publish settings I selected the option Exclude files from App_Data folder and when importing the package into IIS7.5 the database is successfully created in the Users\AppData\... folder with a different name (XYZWebDB).
The site opens correctly and pages that have an asp:SQLDataSource element bind data correctly based on the connection string name and SQL select command. Other pages that retrieve the connection string with C# simply hang and don’t do anything.
To get it successfully imported it into IIS and without modifying any IIS options I removed the whole web.config section runAllManagedModulesForAllRequests. I decided to do this after reading that a lot of people have difficulties with this keyword and not finding any clear cut answers, unless digging into IIS and the allow/deny options. I don’t want to get into IIS. I simply want to test the app and uploaded to the web!
Perhaps I am not doing things right. The above left me with the following questions:
Any help would be very much appreciated and many thanks in advance to all the people reading this.
Have a wonderful day…
Regards
Michael
PS The following connection strings were used:
The asp:SQLDataSource setting is:
<asp:SqlDataSource ID="SqlDataSourceProduct" DataSourceMode="DataReader" ConnectionString="<%$ ConnectionStrings:ApplicationServices%>" SelectCommand="SELECT Product, AUDinclGST FROM tbl_product WHERE ProductID < 11" runat="server"></asp:SqlDataSource>
The C# get connection string is copied from MSDB Library:
// Get SQL Connection String
static private string dsGetConnectionString() {
// Get the application path needed to obtain
// the application configuration file.
string appName = Environment.GetCommandLineArgs()[0];
string appexePath = System.IO.Path.Combine(Environment.CurrentDirectory, appName);
// Get the application configuration file.
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(appexePath);
// Get the connectionStrings section.
ConnectionStringsSection csSection = config.ConnectionStrings;
// Select the section.
ConnectionStringSettings cs = csSection.ConnectionStrings[0];
// Return connection string.
return cs.ConnectionString; }
Mudasir.Khan
All-Star
15346 Points
3142 Posts
Re: Why do asp:SQLDataSource and C# connectionString point to two different configs?
Jul 29, 2012 12:46 PM|LINK
are you not reading this from web.config ?
because by default we get the values for reading.
if you may create a static property and access it
--Michael--
Member
46 Points
21 Posts
Re: Why do asp:SQLDataSource and C# connectionString point to two different configs?
Jul 29, 2012 03:38 PM|LINK
Hi Mudasir.Khan,
and yes the asp:SQLDataSource is bound to the named instance "ApplicationServices" in the connectionStrings section of the web.config file.
But the C# code is somehow pointing to the WebDev.WebServer40.exe.config in folder:
C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\
I am not sure what to do, it works fine - in development!
Regards
Michael
--Michael--
Member
46 Points
21 Posts
Re: Why do asp:SQLDataSource and C# connectionString point to two different configs?
Aug 02, 2012 10:33 AM|LINK
I changed in C# the way the connection string is gotten. The below is now looking into the web.config file: