Monday, March 19, 2012

Creating SQL Data base

Hi,
I want to create SQL Data and default user base using Visual Basic. any body help me to create it
thanks for your advise
byeif you have a script file
you can use shell command or winexec api, e.g.

winexec("osql.exe -S -usa -p -iscriptfile", SW_HIDE)

about osql' parameters, to see sql server online help|||You can execute script string in ADODB.Command object.|||The simplest way is:

Dim cn As ADODB.Connection

Set cn = New ADODB.Connection
cn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=master;Data Source=myserver"
cn.Execute "create database test"
cn.Close
Set cn = Nothing

You can get more fancy with this. If you will use this more than once I would recommend creating a stored procedure that you would execute. This can also be used if you need to pass parameters like database name, location, size ...

If you are using vb.net take a look at the following ms article:

article (http://support.microsoft.com/default.aspx?scid=kb;en-us;Q305079&ID=kb;en-us;Q305079&SD=MSDN)

No comments:

Post a Comment