hello I need to script my Db, tables and storedprocedures. so i can create another same DB
Dim con As New SqlConnection(DBClass.Config.DBString)
Dim cmdName As String = File.OpenText("pro.sql").ReadToEnd()
Dim cmd As New SqlCommand(cmdName, con)
cmd.CommandType = CommandType.Text
con.Open()
Try
cmd.ExecuteNonQuery()
MessageBox.Show("DB Created")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
con.Close()
Any suggestions plzzzzzzzzzzz
you can right click on your DB and generate scripts for all objects in your DB. If you want to do it programmatically run the profiler and see what mgmt studio is doing to generate the scripts. You can do the same from your application.|||If SMO is used (liek in SSMS) There is some more information needed than this which is queried fromt he SQl Server. I would suggest using the SMO namespace for creating your script. SMO is the successor of DMO and has a dependency walker to keep track of dependent objects.HTH, Jens K. Suessmeyer.
http://www.sqlserver2005.de|||
if ur using sqlserver 2000 make use of the sql DMO functions...simple functions to achive wat u want... examples at C:\Program Files\Microsoft SQL Server\80\Tools\Devtools\Samples\Sqldmo
similarly for SS 2005 though DMO are supported(just for backward compatibility,wont be there in future editions), u can use SMO,which offers many additional functions...
|||Can you give me some more details about that plz|||have you looked in the folder in the post?
There should be a demo for you to look at which should give you more info as you requested.|||
I have no problem creating Data Base, I just want to have SQLScript(tables and procedures), this file called db.sql
Then I want to use this code, why Im having problem creating the procedures?
Dim con As New SqlConnection(DBClass.Config.DBString)
Dim cmdName As String = File.OpenText("db.sql").ReadToEnd()
Dim cmd As New SqlCommand(cmdName, con)
cmd.CommandType = CommandType.Text
con.Open()
Try
cmd.ExecuteNonQuery()
MessageBox.Show("DB Created")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
con.Close()
|||hmmm,we seem to be duplicating ourselves as you have an open topic here; http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1006948&SiteID=1
In this thread I provide you with a code example, the example lets you read a script in a StreamReader, then execute this script on a database.
Please be careful you dont upset people posting the same questions in multiple topics
No comments:
Post a Comment