Thursday, March 29, 2012

Failed to open a connection to the database

Hello,

I receivethis error when choosing the data connection in TableAdapter Wizard for me toreference the ASPNETDB.mdf database.

Failed to open a connection to the database

"The header for file'C:\Inetpub\wwwroot\Websites4\App_Data\ASPNETDB.MDF is not valid database
file header. The FILE SIZE property is incorrect.
An attempt to attach an auto-named database exists, orspecified file cannot
be opened, or it is located on UNC share."

Check the connection and try again.


I already have the connection at config but the errorpersists.

...
<connectionStrings>
<addname="ConnectionString1" connectionString="DataSource=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\mydatabase.mdf;IntegratedSecurity=True"providerName="System.Data.SqlClient" />
<addname="ASPNETDBConnectionString1" connectionString="DataSource=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;IntegratedSecurity=True"providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
...

cheers,
imperialx

My friend,

Why don't you use Dynamic Database connection to solve your problem.

in App_Data. ASPNET.MDF file creates automatically when u using Page.Theme or something. So please check it.

Thanks.

|||

Hi kaushikpatel71,

Instead of simple dragging the table to the form, I do this as you suggested.

...
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False"
EmptyDataText="There are no data records to display." CellPadding="4" ForeColor="#333333" GridLines="None">
<Columns>
<asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="LastActivityDate" HeaderText="LastActivityDate" SortExpression="LastActivityDate" />
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<HeaderStyle BackColor="Maroon" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</asp:Content
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
DataUserList()
End If
End Sub

Protected Sub DataUserList()
GridView1.DataSource = Membership.GetAllUsers
GridView1.DataBind()
End Sub
...

Thank you so much!

cheers,
imperialx


sql

No comments:

Post a Comment