Loading ...

error while running a sql script ?

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  data access   » error while running a sql script ?

error while running a sql script ?

Posts under the topic: error while running a sql script ?

Posted: 8/27/2010

Lurker 312  points  Lurker
  • Joined on: 8/27/2010
  • Posts: 54

I have one Database A .mdf

now i want to create Database B.mdf just like Database A

I generated a script of Database A .mdf

and created fresh Database B.mdf

Now, when i try to run the generated script against Database B, i get this error, why ? how to fix it ?

sql error

 

 


Posted: 8/27/2010

Lurker 312  points  Lurker
  • Joined on: 8/27/2010
  • Posts: 54

For your information:

I am using Visual Studio 2008 ...

I have checked in my script it is:

SET ANSI_NULLS ON
GO

and i have also tried to save the sql script in notepad as: ANSI, UTF-8 and UNICODE

and then i copied from txt file to query but still doesn't work and getting the same error

 

and these are the option that i selected/used while creating my script:

s

 

 


Posted: 8/27/2010

Guru 16518  points  Guru
  • Joined on: 4/19/2009
  • Posts: 483

Mike, 

Why don't you go for Copy Database Wizard


Posted: 8/27/2010

Lurker 312  points  Lurker
  • Joined on: 8/27/2010
  • Posts: 54

Hello, raghav,

as i mentioned above i am using Visual Studio, i don't have SQL Server Management studio

 

 


Posted: 8/27/2010

Guru 16518  points  Guru
  • Joined on: 4/19/2009
  • Posts: 483

Can you show your script ?


Posted: 8/27/2010

Guru 16518  points  Guru
  • Joined on: 4/19/2009
  • Posts: 483
  Answered

Mike, 

I think your script might be like this :

SELECT * FROM TABLE1 GO SELECT * FROM TABLE2 GO SELECT * FROM TABLE3 GO SELECT * FROM TABLE4 GO 

i.e GO statement in a single line 
Now you need to have a line break after each GO in your script file. Okay doing manually is a pain therefore I just made a sample code for it:
#region Using Directives

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Text;

#endregion

public class Example
{
    class Test
    {
        static void Main()
        {
            AddLineBreaks("D:\\test.sql");
        }

        private static void AddLineBreaks(string path)
        {
            // Open a file for reading
            StreamReader streamReader = File.OpenText(path);
            // Now, read the entire file into a strin
            string contents = streamReader.ReadToEnd();
            streamReader.Close();

            // Write the modification into the same fil
            StreamWriter streamWriter = File.CreateText(path);

            streamWriter.Write(contents.Replace("GO", "\r\nGO\r\n"));
            streamWriter.Close();
        }
    }
}



Above I assumed that you script file is situated at D:\\test.sql and it contains this data
SELECT * FROM TABLE1 GO SELECT * FROM TABLE2 GO SELECT * FROM TABLE3 GO SELECT * FROM TABLE4 GO 
Now after running the sample code the script will become:
SELECT * FROM TABLE1 
GO
 SELECT * FROM TABLE2 
GO
 SELECT * FROM TABLE3 
GO
 SELECT * FROM TABLE4 
GO
 
And now run this script to create your db.


Posted: 8/28/2010

Lurker 312  points  Lurker
  • Joined on: 8/27/2010
  • Posts: 54

Hello raghav,

thanks for writing that sample problem for me but the problem is my script is already like that:

my script is something like this:

 

****** Object:  ForeignKey [FK__aspnet_Me__Appli__276EDEB3]    Script Date: 08/27/2010 11:46:25 ******/
IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK__aspnet_Me__Appli__276EDEB3]') AND parent_object_id = OBJECT_ID(N'[dbo].[aspnet_Membership]'))
ALTER TABLE [dbo].[aspnet_Membership] DROP CONSTRAINT [FK__aspnet_Me__Appli__276EDEB3]
GO
/****** Object: ForeignKey [FK__aspnet_Me__UserI__286302EC] Script Date: 08/27/2010 11:46:25 ******/
IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK__aspnet_Me__UserI__286302EC]') AND parent_object_id = OBJECT_ID(N'[dbo].[aspnet_Membership]'))
ALTER TABLE [dbo].[aspnet_Membership] DROP CONSTRAINT [FK__aspnet_Me__UserI__286302EC]
GO
/****** Object: ForeignKey [FK__aspnet_Pa__Appli__59063A47] Script Date: 08/27/2010 11:46:25 ******/
IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK__aspnet_Pa__Appli__59063A47]') AND parent_object_id = OBJECT_ID(N'[dbo].[aspnet_Paths]'))
ALTER TABLE [dbo].[aspnet_Paths] DROP CONSTRAINT [FK__aspnet_Pa__Appli__59063A47]
GO
/****** Object: ForeignKey [FK__aspnet_Pe__PathI__5EBF139D] Script Date: 08/27/2010 11:46:25 ******/
IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK__aspnet_Pe__PathI__5EBF139D]') AND parent_object_id = OBJECT_ID(N'[dbo].[aspnet_PersonalizationAllUsers]'))
ALTER TABLE [dbo].[aspnet_PersonalizationAllUsers] DROP CONSTRAINT [FK__aspnet_Pe__PathI__5EBF139D]


GRANT EXECUTE ON [dbo].[aspnet_Membership_UnlockUser] TO [aspnet_Membership_FullAccess] AS [dbo]
GO
GRANT EXECUTE ON [dbo].[aspnet_Membership_UpdateUser] TO [aspnet_Membership_FullAccess] AS [dbo]
GO
GRANT EXECUTE ON [dbo].[aspnet_Membership_UpdateUserInfo] TO [aspnet_Membership_BasicAccess] AS [dbo]


END
GO



somebody told me to eliminate "GO" as i am using Visual Studio and GO is only for SQL server management studio

i evenr tried script by eliminating "Go" then i got this error:

 

dd

 

 


Posted: 8/28/2010

Guru 16518  points  Guru
  • Joined on: 4/19/2009
  • Posts: 483

Mike, I need to see your full SQL script. 


Posted: 8/30/2010

Lurker 312  points  Lurker
  • Joined on: 8/27/2010
  • Posts: 54

Hello rajneesh,  just wanted to give you a good news that i ran the script on SSMS 2005 on someone else's machine (as i don't have it) and it worked !!!

Can you help me with this issue ? i am trying to install SSMS 2008 and facing lot of problem, i have posted my issue here:

http://strivingprogrammers.com/boards/t/38/how-to-connect-to-local-instance-of-sql-server-2008-management-studio-express-.aspx


Posted: 8/30/2010

Contributor 4863  points  Contributor
  • Joined on: 11/27/2008
  • Posts: 79

asp__developer said:

user="Mike Williams"]Can you help me with this issue ? i am trying to install SSMS 2008 and facing lot of problem, i have posted my issue here:

Mike,

Can you please post your new query as a new post on the forums here? It would benefit other CodeAsp.Net members too.

Thanks,

Vivek


Posted: 8/30/2010

Lurker 312  points  Lurker
  • Joined on: 8/27/2010
  • Posts: 54

[quote user="Vivek Thakur"]

Mike,

Can you please post your new query as a new post on the forums here? It would benefit other CodeAsp.Net members too.

Thanks,

Vivek

[/quote]

 

Hello vivek, here it is:

http://www.codeasp.net/forums/asp-net-topics/data-access/517/how-to-connect-to-local-instance-of-sql-server-2008-management-studio-express


Posted: 9/1/2010

Professional 8495  points  Professional
  • Joined on: 5/3/2010
  • Posts: 389

@Mike, can you please close this thread. As far as I've seen, the issue is resolved :).


Page 1 of 1 (12 items)