我需要知道如何配置我的asp.net web.config文件,以便连接到我的数据库的字符串。这是我目前在文件中的代码:
<?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>
我需要整合的连接字符串如下:
server=214187-1;database=storeboard;uid=stuser;pwd=MyPassword
以下页面需要连接字符串:
<%@ 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>
非常感谢任何有关此问题的帮助......
最诚挚的问候, 保罗
答案 0 :(得分:1)
绝对是您需要的所有内容is here,但您基本上将以下标记添加到web.config的根:
<connectionStrings>
<add
name="NorthwindConnectionString"
connectionString="server=214187-1;database=storeboard;uid=stuser;pwd=MyPassword"
providerName="System.Data.SqlClient"
/>
</connectionStrings>
并通过以下方式阅读:
ConfigurationManager.ConnectionStrings.ConnectionStrings["NorthwindConnectionString"];
你可以用google解决这个问题。