I attempting to store my MySql connection string in my web.config file and I keep getting an error. My web.config file looks like the following:
My code that ues the connectionstring looks like the following:
Now the connection worked fine until I added it to the web.config file. After adding it to the web.config file I get the following error:
Any Ideas?
Thank you, Chester
Code:
<configuration>
<connectionStrings>
<add name="TestIt" connectionString="Server=localhost;user id=MyUser;password=MyPW;database=test;"
providerName="mysql.data.mysqlclient"/>
</connectionStrings>
<system.web>
<sessionState timeout="60" cookieless="AutoDetect" regenerateExpiredSessionId="true" />
<compilation debug="true" strict="false" explicit="true">
<assemblies>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies></compilation>
<pages>
<namespaces>
<clear/>
<add namespace="System"/>
<add namespace="System.Collections"/>
<add namespace="System.Collections.Specialized"/>
<add namespace="System.Configuration"/>
<add namespace="System.Text"/>
<add namespace="System.Text.RegularExpressions"/>
<add namespace="System.Web"/>
<add namespace="System.Web.Caching"/>
<add namespace="System.Web.SessionState"/>
<add namespace="System.Web.Security"/>
<add namespace="System.Web.Profile"/>
<add namespace="System.Web.UI"/>
<add namespace="System.Web.UI.WebControls"/>
<add namespace="System.Web.UI.WebControls.WebParts"/>
<add namespace="System.Web.UI.HtmlControls"/>
</namespaces>
</pages>
<authentication mode="Forms"/>
</system.web>
</configuration>
My code that ues the connectionstring looks like the following:
Code:
connMyTCO.ConnectionString = "<%$ connectionStrings:TestIt %>"
Now the connection worked fine until I added it to the web.config file. After adding it to the web.config file I get the following error:
Code:
Index was outside the bounds of the array.
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.IndexOutOfRangeException: Index was outside the bounds of the array.
Source Error:
Line 17: Private Sub OpenDB()
Line 18: connMyTCO = New MySqlConnection
Line 19: connMyTCO.ConnectionString = "<%$ connectionStrings:TestIt %>"
Line 20: Try
Line 21: connMyTCO.Open()
Source File: C:\WebSites\TCO2\App_Code\DataTier.vb Line: 19
Any Ideas?
Thank you, Chester