Results 1 to 3 of 3

Thread: Creating SQL Databases in VB.NET

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    12

    Exclamation Creating SQL Databases in VB.NET

    -- Newbie Warning!! --

    Hi Guys,

    I was just doing some coding which included checking to see if a SQL database existed and creating one if there wasnt. It took me a long time to debug the following issue I was having with the code...

    I discovered that you actually have to wait a short period of time for the SQL Server to create the database before you can open it!! In the end I had to throw in a Thread.Sleep(5000) to give my PC enough time to create the database before using it.


    The point of this thread is... are there any other tricks like the one above that people like me should know about when dealing with SQL databases??

    Hang on, I'm not finished yet!! The following code checks to see if a database exists. Question, is there a better and cleaner way to do the same thing without relying on a error to happen??!!

    Code:
            Dim sqlDBConn As New SqlConnection
    
    
            Try
                  sqlDBConn = New SqlConnection("Initial Catalog=New_Database; Data Source=localhost; uid=sa")
    
                  sqlDBConn.Open()
            Catch ex As Exception
                  ... 'create database code
                  ...
            End Try

    Your help would be greatly appreciated.


    soulcode.

  2. #2

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    12
    Thanks man, that does help!!









    soulcode
    Last edited by soulcode; Feb 21st, 2004 at 05:27 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width