Click here to Skip to main content
12,629,804 members (28,046 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB 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 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
Posted 22-Nov-12 18:19pm
Rate this: bad
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)

Catch ex As Exception
MsgBox("Error : " & ex.Message)
If conn.State = ConnectionState.Open Then
End If
End Try
Rate this: bad
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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161205.3 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2016
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