Showing posts with label mdf. Show all posts
Showing posts with label mdf. Show all posts

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

Friday, March 9, 2012

Fail to attach to MDF file

I tried to use sp_attach_single_file_db to attach to a MDF file which is probably corrupted in a power failure. But, whenever I run this stored procedure, I get some error message like
Change language setting to us_english
Server: msg 945, Level 14, State 2, line 1
Database 'AlbumSQL' can not be opened because some of the files could not be activated.
Server: Msg 1813, Level 16, State 2, Line 1
Could not open new database 'AlbumSQL'. CREATE DATABASE is aborted.
There is also a Ldf file in the same folder, but when I tried to use sp_attach_db, I get the other message
Server: Msg 5172, Level 16, State 15, Line 1
The header for file 'd:\data\albumsql_log.ldf' is not a valid database file header. The PageAudit property is incorrect.
Can you help me some hint to solve this problem? Thanks.
-Alex HuangIS it possible that there is more than one data file.. Attach single file db
only works when there is only one data file... (Based on the error message,
that kind of sounds like it might be happening.)
Otherwise it is probably time to open a call to PSS>
--
Wayne Snyder, MCDBA, SQL Server MVP
Computer Education Services Corporation (CESC), Charlotte, NC
www.computeredservices.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Alex Huang" <alexh@.ulead.com> wrote in message
news:3DBA8115-8DCC-4853-8ED5-F53B15619452@.microsoft.com...
> I tried to use sp_attach_single_file_db to attach to a MDF file which is
probably corrupted in a power failure. But, whenever I run this stored
procedure, I get some error message like
> Change language setting to us_english
> Server: msg 945, Level 14, State 2, line 1
> Database 'AlbumSQL' can not be opened because some of the files could not
be activated.
> Server: Msg 1813, Level 16, State 2, Line 1
> Could not open new database 'AlbumSQL'. CREATE DATABASE is aborted.
> There is also a Ldf file in the same folder, but when I tried to use
sp_attach_db, I get the other message
> Server: Msg 5172, Level 16, State 15, Line 1
> The header for file 'd:\data\albumsql_log.ldf' is not a valid database
file header. The PageAudit property is incorrect.
> Can you help me some hint to solve this problem? Thanks.
> -Alex Huang

Sunday, February 19, 2012

Extracting file name

I have a file name in a variable with full path
set @.f = 'C:\DIRECTORY1\DIRECTORY2\DIRECTORY3\FILENAME.MDF' .
How do I extract the file name, discarding the path. In the
above example I want to get FILENAME.MDF
TIA
Try,
declare @.f varchar(255)
set @.f = 'C:\DIRECTORY1\DIRECTORY2\DIRECTORY3\FILENAME.MDF'
select right(@.f, charindex('\', reverse(@.f)) - 1)
AMB
"Data Cruncher" wrote:

> I have a file name in a variable with full path
> set @.f = 'C:\DIRECTORY1\DIRECTORY2\DIRECTORY3\FILENAME.MDF' .
> How do I extract the file name, discarding the path. In the
> above example I want to get FILENAME.MDF
> TIA
>
|||Alejandro Mesa wrote:
> Try,
> declare @.f varchar(255)
> set @.f = 'C:\DIRECTORY1\DIRECTORY2\DIRECTORY3\FILENAME.MDF'
> select right(@.f, charindex('\', reverse(@.f)) - 1)
I don't think the above one gives me the result I want,
but anyhow you gave me the idea. This one works
set @.datafile = substring(@.filename,
(len(@.filename) - charindex('\',reverse(@.filename)) +
2),
len(@.filename))
it print FILENAME.MDF
|||> I don't think the above one gives me the result I want,
Did you test it?
use northwind
go
declare @.f varchar(255)
set @.f = 'C:\DIRECTORY1\DIRECTORY2\DIRECTORY3\FILENAME.MDF'
select right(@.f, charindex('\', reverse(@.f)) - 1)
go
Result:
FILENAME.MDF
AMB
"Data Cruncher" wrote:

> Alejandro Mesa wrote:
> I don't think the above one gives me the result I want,
> but anyhow you gave me the idea. This one works
> set @.datafile = substring(@.filename,
> (len(@.filename) - charindex('\',reverse(@.filename)) +
> 2),
> len(@.filename))
> it print FILENAME.MDF
>

Extracting file name

I have a file name in a variable with full path
set @.f = 'C:\DIRECTORY1\DIRECTORY2\DIRECTORY3\FIL
ENAME.MDF'.
How do I extract the file name, discarding the path. In the
above example I want to get FILENAME.MDF
TIATry,
declare @.f varchar(255)
set @.f = 'C:\DIRECTORY1\DIRECTORY2\DIRECTORY3\FIL
ENAME.MDF'
select right(@.f, charindex('', reverse(@.f)) - 1)
AMB
"Data Cruncher" wrote:

> I have a file name in a variable with full path
> set @.f = 'C:\DIRECTORY1\DIRECTORY2\DIRECTORY3\FIL
ENAME.MDF'.
> How do I extract the file name, discarding the path. In the
> above example I want to get FILENAME.MDF
> TIA
>|||Alejandro Mesa wrote:
> Try,
> declare @.f varchar(255)
> set @.f = 'C:\DIRECTORY1\DIRECTORY2\DIRECTORY3\FIL
ENAME.MDF'
> select right(@.f, charindex('', reverse(@.f)) - 1)
I don't think the above one gives me the result I want,
but anyhow you gave me the idea. This one works
set @.datafile = substring(@.filename,
(len(@.filename) - charindex('',reverse(@.filename)) +
2),
len(@.filename))
it print FILENAME.MDF|||> I don't think the above one gives me the result I want,
Did you test it?
use northwind
go
declare @.f varchar(255)
set @.f = 'C:\DIRECTORY1\DIRECTORY2\DIRECTORY3\FIL
ENAME.MDF'
select right(@.f, charindex('', reverse(@.f)) - 1)
go
Result:
FILENAME.MDF
AMB
"Data Cruncher" wrote:

> Alejandro Mesa wrote:
> I don't think the above one gives me the result I want,
> but anyhow you gave me the idea. This one works
> set @.datafile = substring(@.filename,
> (len(@.filename) - charindex('',reverse(@.filename)) +
> 2),
> len(@.filename))
> it print FILENAME.MDF
>

Extracting file name

I have a file name in a variable with full path
set @.f = 'C:\DIRECTORY1\DIRECTORY2\DIRECTORY3\FILENAME.MDF'.
How do I extract the file name, discarding the path. In the
above example I want to get FILENAME.MDF
TIATry,
declare @.f varchar(255)
set @.f = 'C:\DIRECTORY1\DIRECTORY2\DIRECTORY3\FILENAME.MDF'
select right(@.f, charindex('\', reverse(@.f)) - 1)
AMB
"Data Cruncher" wrote:
> I have a file name in a variable with full path
> set @.f = 'C:\DIRECTORY1\DIRECTORY2\DIRECTORY3\FILENAME.MDF'.
> How do I extract the file name, discarding the path. In the
> above example I want to get FILENAME.MDF
> TIA
>|||Alejandro Mesa wrote:
> Try,
> declare @.f varchar(255)
> set @.f = 'C:\DIRECTORY1\DIRECTORY2\DIRECTORY3\FILENAME.MDF'
> select right(@.f, charindex('\', reverse(@.f)) - 1)
I don't think the above one gives me the result I want,
but anyhow you gave me the idea. This one works
set @.datafile = substring(@.filename,
(len(@.filename) - charindex('\',reverse(@.filename)) +
2),
len(@.filename))
it print FILENAME.MDF|||> I don't think the above one gives me the result I want,
Did you test it?
use northwind
go
declare @.f varchar(255)
set @.f = 'C:\DIRECTORY1\DIRECTORY2\DIRECTORY3\FILENAME.MDF'
select right(@.f, charindex('\', reverse(@.f)) - 1)
go
Result:
FILENAME.MDF
AMB
"Data Cruncher" wrote:
> Alejandro Mesa wrote:
> > Try,
> >
> > declare @.f varchar(255)
> >
> > set @.f = 'C:\DIRECTORY1\DIRECTORY2\DIRECTORY3\FILENAME.MDF'
> >
> > select right(@.f, charindex('\', reverse(@.f)) - 1)
> I don't think the above one gives me the result I want,
> but anyhow you gave me the idea. This one works
> set @.datafile = substring(@.filename,
> (len(@.filename) - charindex('\',reverse(@.filename)) +
> 2),
> len(@.filename))
> it print FILENAME.MDF
>