0

I need to know how to configure my asp.net web.config file so that is has connection string to my database. Here is the code I have in the file at this time:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <tracing>
            <traceFailedRequests>
                <add path="*.asp">
                    <traceAreas>
                        <add provider="ASP" verbosity="Verbose" />
                        <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
                        <add provider="ISAPI Extension" verbosity="Verbose" />
                        <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI" verbosity="Verbose" />
                    </traceAreas>
                    <failureDefinitions statusCodes="500" />
                 </add>
            </traceFailedRequests>
        </tracing>
        <handlers>
            <remove name="AboMapperCustom-66406" />
        </handlers>
        <httpErrors errorMode="DetailedLocalOnly">
            <remove statusCode="412" subStatusCode="-1" />
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" path="/handle404.asp" responseMode="ExecuteURL" />
        </httpErrors>
    </system.webServer>
</configuration>

The connection string I need to integrate is as follows:

server=214187-1;database=storeboard;uid=stuser;pwd=MyPassword

The connection string is required for the following page:

<%@ Page Language="VB" EnableSessionState="True" %>
<%@Import Namespace="System" %>
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.SqlClient" %>
<%@Import Namespace="System.Configuration" %>
<%@Import Namespace="System.web" %>
<%@Import Namespace="System.Net" %>
<%@Import Namespace="System.Net.Mail" %>
<%@Import Namespace="System.Security.Cryptography" %>
<%@Import Namespace="System.Text" %>

    <script language="vbscript" runat="server">
    Dim UserName As String
    Dim oConn As SqlConnection
    Dim oCmd1 As SqlCommand
    Dim oCmd2 As SqlCommand
    Dim oCmd3 As SqlCommand
    Dim aConfig As ConfigurationSettings
    Dim strConn As String
    Dim strSQL As String
    Dim LastActivity As string 
    Dim ToAddress As String
    Dim ToName As String
    Dim BatchMailID as Integer
    Dim SessionID As String
    Dim Subject As String
    Dim Inactive as Boolean
    Dim Message As String
    Dim StillActive As Boolean = False

    Dim G_COOKIEROOT AS String = "STOREBOARD"



    Private Sub Page_Load()
        Dim dr As SqlDataReader

        SessionID = Request.Cookies(G_COOKIEROOT)("SESSIONID")
        Session("SessionID") = SessionID
        Response.Cookies(G_COOKIEROOT)("SESSIONID") = SessionID

        strConn = ConfigurationManager.AppSettings("ConnectionString")
        oConn = New SqlConnection(strConn)


        oConn.Open()
        If Trim(SessionID & "") <> "" Then
            strSQL = "sp_SessionData @MODE='UPDATEACTIVITY',@SessionID='" & SessionID & "'"
            oCmd1 = New SqlCommand(strSQL, oConn)
            dr = oCmd1.ExecuteReader()
            While dr.Read()
                StillActive = dr("StillActive")
            End While
            dr.Close()

        End If


    End Sub





</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ASP.NET Status Checker</title>
<meta http-equiv="refresh" content="60" />
</head>
<body>
SessionID: <%=SessionID%><br/>
<%=Now()%>
</body>
</html>

Any help with this issue would be greatly appreciated...

Best Regards, Paul

1 Answer 1

1

Absolutely everything you need is here but you basically add the following tags to the root of web.config:

<connectionStrings>
  <add 
    name="NorthwindConnectionString" 
    connectionString="server=214187-1;database=storeboard;uid=stuser;pwd=MyPassword"
    providerName="System.Data.SqlClient"
  />
</connectionStrings>

and read it via:

ConfigurationManager.ConnectionStrings.ConnectionStrings["NorthwindConnectionString"];

You could've solved this with google.

Sign up to request clarification or add additional context in comments.

2 Comments

I have tried implementing this code but the aspx page doesn't load.. it is throwing an 404 error even though the page is definitely on the server and in the correct location. The web.config loads without errors
Must be a different problem, your server on? Right url, port etc?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.