Click here to Skip to main content
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
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 OriginalGriff 328
1 Sergey Alexandrovich Kryukov 295
2 Gihan Liyanage 292
3 ClimerChinna 222
4 Abhinav S 187
0 Sergey Alexandrovich Kryukov 8,213
1 OriginalGriff 7,089
2 CPallini 2,598
3 Richard MacCutchan 1,925
4 Abhinav S 1,778


Advertise | Privacy | Mobile
Web01 | 2.8.140826.1 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2014
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