G
gv
Hi all,
Not sure if I'm posting in the right newsgroup
I have devolped a program in VB.NET and the first thing I do is check to see
if
the database Exist. Well the first time I run the program I get a error and
then breaks to
the line "CmdCheckSP.ExecuteNonQuery()".
I run it again and then presto, no problem. I'm confused?
Can someone please help me.
Public Sub SQLConnection()
Dim StrConn As String = "User ID=" & loginuser & ";" & _
"Password=" & loginpass & ";" & _
"Initial Catalog=" & loginDatabase & ";" & _
"Data Source=" & loginIPaddress
SQLConn = New SQLConnection(StrConn)
If SQLConn.State = ConnectionState.Open Then
SQLConn.Close()
End If
End Sub
Friend Function IsDatabaseExists(ByVal DBname) As Boolean
Dim SQLDataBase As String = _
" CREATE PROCEDURE CheckSQLDatabase
" & vbCrLf & _
"
" & vbCrLf & _
" @out Integer OUTPUT
" & vbCrLf & _
" AS
" & vbCrLf & _
" IF exists (select * from master.dbo.sysdatabases
where name = " & vbCrLf & _
"'" & DBname & "'" & " )
" & vbCrLf & _
" BEGIN
" & vbCrLf & _
" set @out = 1
" & vbCrLf & _
" END
" & vbCrLf & _
" ELSE
" & vbCrLf & _
" BEGIN
" & vbCrLf & _
" set @out = 0
" & vbCrLf & _
" END "
'Call main connection
SQLConnection()
Dim CmdCheckSP As New SqlCommand(SQLDataBase)
CmdCheckSP.Connection = SQLConn
SQLConn.Open()
CmdCheckSP.ExecuteNonQuery()
thanks
Gerry
Not sure if I'm posting in the right newsgroup
I have devolped a program in VB.NET and the first thing I do is check to see
if
the database Exist. Well the first time I run the program I get a error and
then breaks to
the line "CmdCheckSP.ExecuteNonQuery()".
I run it again and then presto, no problem. I'm confused?
Can someone please help me.
Public Sub SQLConnection()
Dim StrConn As String = "User ID=" & loginuser & ";" & _
"Password=" & loginpass & ";" & _
"Initial Catalog=" & loginDatabase & ";" & _
"Data Source=" & loginIPaddress
SQLConn = New SQLConnection(StrConn)
If SQLConn.State = ConnectionState.Open Then
SQLConn.Close()
End If
End Sub
Friend Function IsDatabaseExists(ByVal DBname) As Boolean
Dim SQLDataBase As String = _
" CREATE PROCEDURE CheckSQLDatabase
" & vbCrLf & _
"
" & vbCrLf & _
" @out Integer OUTPUT
" & vbCrLf & _
" AS
" & vbCrLf & _
" IF exists (select * from master.dbo.sysdatabases
where name = " & vbCrLf & _
"'" & DBname & "'" & " )
" & vbCrLf & _
" BEGIN
" & vbCrLf & _
" set @out = 1
" & vbCrLf & _
" END
" & vbCrLf & _
" ELSE
" & vbCrLf & _
" BEGIN
" & vbCrLf & _
" set @out = 0
" & vbCrLf & _
" END "
'Call main connection
SQLConnection()
Dim CmdCheckSP As New SqlCommand(SQLDataBase)
CmdCheckSP.Connection = SQLConn
SQLConn.Open()
CmdCheckSP.ExecuteNonQuery()
thanks
Gerry