简体   繁体   中英

“Parser Error Message: The server tag is not well formed” in ASP.NET with Web.config String?

I've got a Parser Error.

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: The server tag is not well formed.

Source Error:

Line 86:     </div>
Line 87:     <div id="divLocalhostOnly" runat="server">
Line 88:         <asp:SqlDataSource ID="sqlData" runat="server"
Line 89:             ConnectionString="<%$ ConnectionStrings:LOCAL_D630 %>"
Line 90:             InsertCommand="INSERT INTO [dbo].[Roster] (" +

Source File: /Member.aspx Line: 88

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1055.0

I suspect it could be how I am trying to use the connection string that I have in my Web.config file, because I have not come across any examples where the SqlDataSource is written using the Web.config 's ConnectionStrings section.

Here is a snipped version of my Web.config :

<configuration>
  <connectionStrings>
    <clear />
    <add name="LOCAL_D630" connectionString="Data Source=D630-PC\SQL5016;Initial Catalog=Table1;User Id=admin;Password=StackOverflow;" providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

Is the problem with my SqlDataSource's ConnectionString?

Can I use the Web.config file to specify the Connection String?

What am I doing wrong?

Yes, using connection string that way should work. I have used it successfully just like you had above.

Can you try the following?

  1. Remove the semicolon at the end of your password in your connectionstring of web.config
  2. Remove the underscore in your connectionstring name.

Here is an example that works (though it connects to oracle db)

 <connectionStrings>
   <add name="ConnectionString" connectionString="Data Source=abc;
    UserID=xxx;password=xxx" providerName="System.Data.OracleClient"/>
 </connectionStrings>

and in your aspx file

 <asp:SqlDataSource ID="OracleDataSource" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
    ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"  
   SelectCommand="select query here">
</asp:SqlDataSource>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM