- Public Shared Function
CheckDatabaseExists(ByVal Server As String, ByVal Database As String) As Boolean - Dim connString As
String = ("Data Source=" _ - + (Server
+ ";Initial Catalog=Master; Integrated Security=True;")) - Dim cmdText As String
= ("SELECT * FROM master.dbo. sysdatabases WHERE NAME=\'" _ - + (
Database + "\'")) - Dim bRet As Boolean =
false - Using sqlConnection
As SqlConnection = New SqlConnection(connString) - sqlConnection.Open
- Using sqlCmd As
SqlCommand = New SqlCommand( cmdText, sqlConnection) - Using reader As
SqlDataReader = sqlCmd. ExecuteReader - bRet = reader.HasRows
- End Using
- End Using
- End Using
- Return bRet
- End Function
- string sqlConnectionString = "
Data Source=FIRSTONE;User ID= sa; Persist Security Info= True;"; - FileInfo file = new
FileInfo("name_of_the_sql_ script.sql"); - string script = file.
OpenText().ReadToEnd(); - string rscript = script.
Replace("GO", ""); - SqlConnection conn = new
SqlConnection( sqlConnectionString); - SqlCommand cmd = new
SqlCommand(rscript, conn); - cmd.Connection.Open();
- cmd.ExecuteNonQuery();
- cmd.Dispose();
- string sqlConnectionString = "
Wednesday, 25 January 2012
check db Existance and execute script
Subscribe to:
Post Comments (Atom)
It is very nice post and help me.
ReplyDeleteIf you want to get more information related to PHP then go http://www.phpcreating.blogspot.com
Thanks
Bhargav Anadkat
Wordpress Development India