www.webdeveloper.com
Results 1 to 7 of 7

Thread: Connect to DB

  1. #1
    Join Date
    Apr 2007
    Posts
    395

    Connect to DB

    Reading a Book that uses a class Method to connect to a DB But I Don't Know how to set it up?

    What does this function Mean is this using a server ALias?
    How do I Setup the DB?
    I think its meant to use these Files But Ive never used this type of DB:
    DB_Attach.bat
    DB_Attach.sql
    Halloween.mdf
    Halloween_log.LDF

    Private Shared Function Connection() As SqlConnection
    Dim ConHalloween As New SqlConnection
    Dim sConnectionString As String = "Data Source=Doug\VSDOTNET;" _
    & "Initial Catalog=Halloween;Integrated Security=SSPI"
    ConHalloween.ConnectionString = sConnectionString
    Return ConHalloween
    End Function

  2. #2
    Join Date
    Jun 2004
    Location
    Kansas City, MO
    Posts
    1,607
    Halloween.mdf Well you can read about it here. This is what it likely is http://www.delphifaq.com/faq/f777.shtml

    Halloween_log.LDF is some kind of a log file

    DB_Attach.bat is a bat file. You should be able to open this with notepad and view its contents

    DB_Attach.sql is most likely a script to create tables and or stored procedures, etc. You can also open this with notepad and view its contents. You would run that script (in my case) in say query analyser and it would create tables, etc.

    That function is basically just a function that you can call to get your connection. IMO this function is not needed as you can put your Connection String in your web.config file.

    Here is an example
    Code:
    Private Sub OpenSqlConnection()
        Dim connectionString As String = Connection()      
    
        Using connection As New SqlConnection(connectionString)
            connection.Open()
        End Using
    End Sub
    
    Private Shared Function Connection() As SqlConnection
        Dim ConHalloween As New SqlConnection
        Dim sConnectionString As String = "Data Source=Doug\VSDOTNET;" _
        & "Initial Catalog=Halloween;Integrated Security=SSPI"
        ConHalloween.ConnectionString = sConnectionString
        Return ConHalloween
    End Function
    Putting this in your web.config file
    Code:
    <connectionStrings>
    	<add name="oConn" connectionString="Data Source=Doug\VSDOTNET;Initial Catalog=Halloween;Integrated Security=SSPI"/>
    </connectionStrings>
    
    'You can then access it like this
    Private Sub OpenSqlConnection()
        Dim connectionString As String = Configurationmanager.AppSettings("oConn").ToString()      
    
        Using connection As New SqlConnection(connectionString)
            connection.Open()
        End Using
    End Sub

  3. #3
    Join Date
    Apr 2007
    Posts
    395

    Db

    Yeah Opened them Up and they are SQL, BAT files.
    The SQL script Reads the .mdf file and logs to the .ldf file.

    I have downloaded MSDE 2000, How can I run this Script to create the Database, Will it Create an Access Database?

  4. #4
    Join Date
    Jun 2004
    Location
    Kansas City, MO
    Posts
    1,607
    I believe the script is for an sql server database. Unless you have Access installed on your machine, nothing can create it for you.

    You might be able to download mySQL which I belive is a free database by Microsoft. You might be able to use that sql script with mySQL but im not 100% sure on that.

    The connection String above is creating a sql connection and if you use a different database other than (I think just) SQL server, youll have to create your connnection a different way (Instead of using sqlconnection i belive it might odbconnection or something similar).

  5. #5
    Join Date
    Apr 2007
    Posts
    395

    SQL Server

    Microsoft Desktop Engine (MSDE) is a stripped back version of SQL Sever without some functionality.

    If I was to use that script with SQL server how could I install it, presuming there is no GUI tools could I use the command line to run the Script.

    Pretty Sure MYSQLs from a Swedish company, Think many opensource guys would vomit at that proposition.

  6. #6
    Join Date
    Apr 2007
    Posts
    395

    Got it

    Ive figured it out, but not in the orthodox way, When I create a DB in Visual Studio it creates a .mdf and .ldf file in C:/program Files/SQL Server/MSSQl/Data

    So I created a DB with the Same name and replaced the files, It registered the tables in VS now?

    But would still be keen to figure out how its meant to be done.

  7. #7
    Join Date
    Jun 2004
    Location
    Kansas City, MO
    Posts
    1,607
    lol, my bad on the mysql, yes it Swedish and not ms. A brain fart perhaps.

    Seeing how I have only dealt with SQL Server and Oracle, I have never had to deal with these types of situations so Im at a lose for words.

    But it sounds like you got it up and running.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles