rahuroy Posted February 17, 2011 Share Posted February 17, 2011 I am writing script for installation of application. Before starting installing i have to verify existence of database and if it exists then i have to drop it.Below is snippet of code where i am connecting to server and running query.But after querying not able to drop database if it exists? Someone can give some suggestions; $fAuthMode - Authorization mode (0 = Windows Logon, 1 = SQL) (default = 0)OnAutoItExitRegister("_Exit")Func _Exit() MsgBox(0,"@ExitCode",@exitCode) EndFuncGlobal $Ignore, $Ini, $Installer, $Pid,$GUID,$squery,$result,$fAuthMode,$xnn,$ynn,$query$Ini = @ScriptDir & "\Install.ini"Global $username = IniRead($INI, "EMSettings", "IS_NET_API_LOGON_USERNAME", "")Global $password = IniRead($INI, "EMSettings", "IS_NET_API_LOGON_PASSWORD", "")Global $sqlserver = IniRead($INI, "EMSettings", "IS_SQLSERVER_SERVER", "")Global $sqlusername = IniRead($INI, "EMSettings", "sqlloginname", "")Global $sqlpwd = IniRead($INI, "EMSettings", "sqlpassword", "")Global $emdbname = IniRead($INI, "EMSettings", "IS_SQLSERVER_DB", "")Global $fAuthMode = IniRead($INI, "EMSettings", "AuthMode", "") ; $fAuthMode - Authorization mode (0 = Windows Logon, 1 = SQL) (default = 0)Global $sQuery="select * from master.dbo.sysdatabases where name =' & $emdbname & '"If $fAuthMode=0 Then $xnn="Provider=SQLOLEDB;Data Source= " & $sqlserver & ";Trusted_Connection=Yes;" $sqlCon = ObjCreate("ADODB.Connection") $sqlCon.Open($xnn) if @error Then MsgBox(0, "ERROR", "Failed to connect to the database") Exit Else MsgBox(0, "Success!", "Connection to database successful!") EndIf $query=_SQLQuery($sqlCon,$sQuery) If $query=1 Then $sqlCon.Execute("DROP DATABASE " & $emdbname) else $ynn="Provider=sqloledb;Data Source=" & $sqlserver & ";Network Library=DBMSSOCN;User ID=" & $sqlusername &";Pwd=" & $sqlpwd & ";" $sqlCon = ObjCreate("ADODB.Connection") $sqlCon.Open($ynn) if @error Then MsgBox(0, "ERROR", "Failed to connect to the database") Exit Else MsgBox(0, "Success!", "Connection to database successful!") EndIf $query=_SQLQuery($sqlCon,$sQuery) MsgBox(0,"",$query) If $query=1 Then $sqlCon.Execute("DROP DATABASE " & $emdbname)EndIfFunc _SQLQuery($sqlCon, $sQuery) If IsObj($sqlCon) Then Return $sqlCon.Execute($sQuery) ReturnEndFunc Link to comment Share on other sites More sharing options...
kylomas Posted February 17, 2011 Share Posted February 17, 2011 rahuroy, Use conoslewrite to verify the value of $query from _SQLQuery. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now