I
Ina
Hello all,
I am newbien in VB.net and I would like to know what is going wrong
with my code.
Imports System
Imports System.Data
Imports System.Data.SqlClient
Module Module1
Sub Main()
Dim ConnectionString As String
Dim reader As SqlDataReader
Dim sql As String
'connection string; just open a connection with sql server ; Do
I need to mention the
'database here even if I did not create it yet
ConnectionString = "server=localhost;uid=xxxxx;pwd=xxxxxx;"
Console.WriteLine("OK")
Dim sqlConn As New SqlConnection(ConnectionString)
'if the database doesn't exist, create it
sql = "USE MASTER GO IF NOT EXISTS (SELECT * FROM sysdatabases
where name = 'TEST') CREATE DATABASE TEST ON PRIMARY GO"
Dim SelectCommand As New SqlClient.SqlCommand(sql, sqlConn)
Try
sqlConn.Open()
Catch ex As Exception
Console.WriteLine("Failed to execute command")
Finally
sqlConn.Close()
End Try
Console.WriteLine("Done")
End Sub
End Module
Probleme: I have the Ok and Done, and not failed to execute command,
but my database has not been created why?
Ina
I am newbien in VB.net and I would like to know what is going wrong
with my code.
Imports System
Imports System.Data
Imports System.Data.SqlClient
Module Module1
Sub Main()
Dim ConnectionString As String
Dim reader As SqlDataReader
Dim sql As String
'connection string; just open a connection with sql server ; Do
I need to mention the
'database here even if I did not create it yet
ConnectionString = "server=localhost;uid=xxxxx;pwd=xxxxxx;"
Console.WriteLine("OK")
Dim sqlConn As New SqlConnection(ConnectionString)
'if the database doesn't exist, create it
sql = "USE MASTER GO IF NOT EXISTS (SELECT * FROM sysdatabases
where name = 'TEST') CREATE DATABASE TEST ON PRIMARY GO"
Dim SelectCommand As New SqlClient.SqlCommand(sql, sqlConn)
Try
sqlConn.Open()
Catch ex As Exception
Console.WriteLine("Failed to execute command")
Finally
sqlConn.Close()
End Try
Console.WriteLine("Done")
End Sub
End Module
Probleme: I have the Ok and Done, and not failed to execute command,
but my database has not been created why?
Ina