MSSQL Connection

Discussion in 'Databases' started by Harry Rorarius, Feb 26, 2019.

  1. Hi all
    Not sure if this is the right place for this question but here goes
    I am using web.config with sql connection string in it and i am getting a error 500.19 internal server error and it marked the line in the web.config with the sql connection string
  2. Elshadriel

    Elshadriel Winhost Staff

    500 errors are difficult to troubleshoot. Can you provide more information? It might be because the markup for the configuration is incorrect.
  3. Well the configuration file works fine on my 2012 development server so not sure what the difference is.
  4. <!--<add key="connString" value=";UID=ID;pwd=pass; database=DB;Integrated Security=False;"/>-->
    <add name="connString" connectionString="Data;UID=ID;pwd=pass; database=DB;Trusted_Connection=False;" providerName="System.Data.SqlClient"/>

    tried both and get same error
  5. HTTP Error 500.19 - Internal Server Error
    The requested page cannot be accessed because the related configuration data for the page is invalid.
    Detailed Error Information:

    Module IIS Web Core
    Notification Unknown
    Handler Not yet determined
    Error Code 0x8007000d
    Config Error Configuration file is not well-formed XML
    Config File \\?\E:\web\herdatas\web.config
    Requested URL
    Physical Path
    Logon Method Not yet determined
    Logon User Not yet determined

    Config Source:
    13: <!--<add key="connString" value=";UID=ID;pwd=Pass; database=DB;Integrated Security=False;"/>-->
    14: <add name="connString" connectionString="Data;UID=ID;pwd=Pass; database=DB;Trusted_Connection=False;" providerName="System.Data.SqlClient"/>
    15: <!-- PayPay parameters-->
  6. Elshadriel

    Elshadriel Winhost Staff

    Hi Harry,

    I have corrected the problem for you. The key is this:

    Config Error Configuration file is not well-formed XML

    Your connection string was in the <appSettings> section (not shown) which uses key-value pair. If you want to use name-connectionString, then you must put that in the <connectionStrings> section and reference it accordingly in your application. Another problem was there was an & in your password. I removed it. You can always check if you have the correct XML markup in Visual Studio. Visual Studio highlights any potential problems. It's not 100% accurate as sometimes, it may highlight markup to be incorrect, but in reality, there isn't a problem. Whenever i see the above error, I just look for problems in Visual Studio.
  7. I did not add these lines in the script

    this is in <appSettings></appSettings> and the & is part of the password
    Besides this configuration was working fine in server 2012. Was using line 13 in the error list for the old server which is commented out.
  8. OK have a new error

    The ConnectionString property has not been initialized.
    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.InvalidOperationException: The ConnectionString property has not been initialized.

    Source Error:

    Line 89:
    Line 90: ' Open the connection and execute the Command
    Line 91: myConnection.Open()
    Line 92: myCommand.ExecuteNonQuery()
    Line 93: myConnection.Close()

    Source File: E:\web\herdatas\Default.aspx.vb Line: 91

    Stack Trace:

    [InvalidOperationException: The ConnectionString property has not been initialized.]
    System.Data.SqlClient.SqlConnection.PermissionDemand() +5977522
    System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection outerConnection) +25
    System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +154
    System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +21
    System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +90
    System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +443
    System.Data.SqlClient.SqlConnection.Open() +96
    Epic_Computer_Common._Default.GetTotal(String EmpID) in E:\web\herdatas\Default.aspx.vb:91
    Epic_Computer_Common._Default..ctor() in E:\web\herdatas\Default.aspx.vb:11
    ASP.default_aspx..ctor() in E:\web\herdatas\Default.aspx.vb:912304
    __ASP.FastObjectFactory_app_web_5jmjwrjw.Create_ASP_default_aspx() +52
    System.Web.Compilation.BuildResultCompiledType.CreateInstance() +31
    System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) +100
    System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +31
    System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context, String requestType, String virtualPath, String path) +37
    System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +339
    System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +48
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +159
  9. Elshadriel

    Elshadriel Winhost Staff

    What I was trying to say was that the markup you had for your connection string was in the wrong section (i.e. appSettings instead of connectionStrings). Your new error is because you are trying to get the connection string from the appSettings section in your code. You need to change your code to pull the information from the connectionStrings section instead now that you have it there. I use the ConfigurationManager class and ConnectionStrings property to do that.
  10. Hi All
    I want to thank you for all the help! I ended up finding out my whole problem was I had "&" in my password and that caused the entire error so the original web.config file works just fine just had to update the password to eliminate the "&"
    <!--<add key="connString" value=";UID=ID;pwd=pass; database=DB;Integrated Security=False;"/>-->
    Elshadriel likes this.

Share This Page