Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-ServerVB.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
Ganeshcse1.9K
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
Your Filters
Interested
Ignored
     
0 Shai Vashdi 456
1 OriginalGriff 183
2 Sergey Alexandrovich Kryukov 171
3 Tadit Dash 160
4 praveen_07 115
0 Sergey Alexandrovich Kryukov 9,280
1 OriginalGriff 5,473
2 Peter Leow 4,100
3 Maciej Los 3,540
4 Abhinav S 3,333


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid