Reputation: 123
I am using a grid view to read data from a local db, but i am getting an unhandled exception.
The page displays these messages :
Illegal characters in path.
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.ArgumentException: Illegal characters in path.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Below is connection string in web.config
<connectionStrings>
<add name="automobileDB"
connectionString="Data Source=(LocalDB)\v11.0;
AttachDbFilename=|DataDirectory|\
automobileDB.mdf; Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
Below is my grid view code in webform:
<asp:SqlDataSource ID="ADDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:automobileDB %>"
SelectCommand="SELECT * FROM [Advertisements]" >
</asp:SqlDataSource>
<div>
<asp:GridView ID="AddGridView" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CssClass="list" DataKeyNames="Id"
DataSourceID="ADDataSource" GridLines="None">
<Columns>
<asp:BoundField DataField="topic" HeaderText="First Name" />
<asp:BoundField DataField="Brand" HeaderText="Last Name" />
<asp:BoundField DataField="Model" HeaderText="Phone" />
<asp:BoundField DataField="Year" HeaderText="Email" />
</Columns>
</asp:GridView>
</div>
What gives the exception here ?
Thank you
Upvotes: 2
Views: 287
Reputation: 14614
Based on the way you write your connection string in web.config, there's some space between |DataDirectory|\
and automobileDB.mdf
. Change your connection string to this:
<connectionStrings>
<add name="automobileDB"
connectionString="Data Source=(LocalDB)\v11.0;
AttachDbFilename=|DataDirectory|\automobileDB.mdf; Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
Upvotes: 1