Click here to Skip to main content
11,705,451 members (50,985 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server VB.NET
Hi all,
I have small doubt thaat I have one .sql file. I want to import that file into my database of asp.net application so that i can reduce time of writing entire tables again. can this possible I know how to import a mdf file but not able to find any solution to import or convert a .sql file to .mdf file or simply loading a .sql file into my existing data base.

Please any one could help me
Thanks
Ganesh
Posted 22-Nov-12 17:19pm
Ganeshcse2.4K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You could read the content of the sql file to a string and then execute it :

Dim sqlFile As String = "C:\script.sql"
Dim sqlText as string= File.ReadAllText(sqlFile)
Dim connStr as string= "Server="& sSqlServerInstance &"; Database="& sDB &"; Integrated Security=SSPI"
Dim conn = New SqlConnection(connStr)

Dim sCmd = New SqlCommand(sqlText, conn)

Try
conn.Open()
sCmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox("Error : " & ex.Message)
Finally
If conn.State = ConnectionState.Open Then
conn.Close()
End If
End Try
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I have installed the SQL Server Management Studio and run the sql fine against the data base. that it and it is the one of the easiest method than writing the code and execute. only one burden is that again we have to install the sql server management studio that's it but if any one is having sql server management studio better follow this method.

Thanks & Regards
Ganesh
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 286
1 OriginalGriff 269
2 ppolymorphe 78
3 Inimicos 60
4 ProgramFOX 50
0 OriginalGriff 9,053
1 Sergey Alexandrovich Kryukov 8,347
2 CPallini 5,189
3 Maciej Los 4,726
4 Mika Wendelius 3,626


Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100