Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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

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
 
Share this answer
 
v2
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900