none
Error in attaching database

    Question

  • Hi all,

    I am attaching database to sqlserver express 2008 through c# code.I tried sp_attach_single_file_db and sp_attachdb procedures.Getting error as  Physical filename may be incorrrect.

    Suppose created a database in vista and when this database is attached in xp system  it shows error as

    C:\Programfiles(x86)\Microsoft Sql Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\xx_log.ldf is incorrect.

    If created a database in xp and when this database is attached in vistasystem  it shows error as

    C:\Program Files\SQL Server Express\MSSQL10.SQLEXPRESS1\MSSQL\DATA\xx_log.LDF" may be incorrect.

    I had also tried strConnString1 = "Data Source=" + strHostName1 + ";AttachDbFilename=C:\\Documents and Settings\\All Users\Project Folder\\xx.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True;";

    Then it shows
    A network related or instance specific error occured while establishing a connection to the sql server.The server was not found or was not accesible.Verify that instance name is correct and that sql server is configured to allow remote connections.

    What would be the reason for this?Any solution for this.

                                                                                                                    Thanks
    Friday, October 23, 2009 4:45 AM

Answers

  • Hello vsn19,

    may can you post the complete Sql statements, so we can have a look at?

    The error points to the LDF file, so it seems to accept the MDF file. The MDF "reminds" the old location of the LDF and under XP you don't have the folder "C:\Programfiles(x86)".

    The SP sp_attach_db provides parameter to address the files that should be attached for the database, so you should add also the LDF file with the new location:
    sp_attach_db [ @dbname= ] 'dbname'
            , [ @filename1= ] 'filename_n' [ ,...16 ] 

    Example from TechNet sp_attach_db:

    EXEC sp_attach_db @dbname = N'AdventureWorks', 
        @filename1 = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_Data.mdf', 
        @filename2 = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_log.ldf';


    Olaf Helper ----------- * cogito ergo sum * errare humanum est * quote erat demonstrandum * Wenn ich denke, ist das ein Fehler und das beweise ich täglich http://olafhelper.over-blog.de
    • Marked as answer by vsn19 Monday, October 26, 2009 5:27 AM
    Friday, October 23, 2009 6:25 AM

All replies

  • Hello vsn19,

    may can you post the complete Sql statements, so we can have a look at?

    The error points to the LDF file, so it seems to accept the MDF file. The MDF "reminds" the old location of the LDF and under XP you don't have the folder "C:\Programfiles(x86)".

    The SP sp_attach_db provides parameter to address the files that should be attached for the database, so you should add also the LDF file with the new location:
    sp_attach_db [ @dbname= ] 'dbname'
            , [ @filename1= ] 'filename_n' [ ,...16 ] 

    Example from TechNet sp_attach_db:

    EXEC sp_attach_db @dbname = N'AdventureWorks', 
        @filename1 = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_Data.mdf', 
        @filename2 = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_log.ldf';


    Olaf Helper ----------- * cogito ergo sum * errare humanum est * quote erat demonstrandum * Wenn ich denke, ist das ein Fehler und das beweise ich täglich http://olafhelper.over-blog.de
    • Marked as answer by vsn19 Monday, October 26, 2009 5:27 AM
    Friday, October 23, 2009 6:25 AM
  • Hi
    Thanks for the post
    Let me try that
    Friday, October 23, 2009 6:53 AM
  • Hi
    Thanks its working
    Monday, October 26, 2009 5:28 AM