1

I get a "System.ArgumentException: Keyword not supported: '<%'." error when I try to access a static class method that will determine what connectionstring I will be using. It is probably a syntax error but I'm not very familiar with accessing class methods from an aspx page.

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%=GetConnectionString.createConnectionString()%>" SelectCommand="SELECT * FROM [Activity]" OnSelecting="SqlDataSource1_Selecting1"></asp:SqlDataSource>
zms6445
  • 317
  • 6
  • 22

1 Answers1

1

Single quotes for inline expressions:

ConnectionString='<%=GetConnectionString.createConnectionString()%>'

Also have a look at this, which explains in which context(s) you can use the syntaxes <%#, <%=, and <%$.

ASP.net Inline Expression Issue

Community
  • 1
  • 1
qJake
  • 16,821
  • 17
  • 83
  • 135
  • I now get Keyword not supported: '<%'. – zms6445 Mar 21 '13 at 19:13
  • How is that different from the error you were getting before? – qJake Mar 21 '13 at 19:19
  • Before it was giving me <%= not supported. I just mistyped it. – zms6445 Mar 21 '13 at 19:21
  • See my edit, read the answer. It's likely you'll need to switch to `<%#` and databind your page since your SqlDataSource is not inside a template. – qJake Mar 21 '13 at 19:23
  • When I add Page.DataBind() to my page load, I receive this message:Default database connection failed. You must set the connection string of the SqlDataSource control in your Web application to the location of your database file. Tell the WebScheduleSqlClientProvider control to use your data source by setting it's DataSourceID property to the UniqueID of that data source control. Also ensure the database file is not marked read-only, and that the user identity under which your Web application runs has full permissions to read/write the database file and the directory containing it. – zms6445 Mar 21 '13 at 19:49
  • Then it's likely you'll have to set the connection string in codebehind. In your page load or page init event: `SqlDataSource1.ConnectionString = GetConnectionString.createConnectionString();` – qJake Mar 21 '13 at 19:54