Results 1 to 2 of 2

Thread: Problem with SQL Express connection string

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    1

    Problem with SQL Express connection string

    Hi all!
    I'm having a problem connecting to SQL Express with VB 2005 Express.
    The Calendar.mdf file is in the same folder as the forms for the project.
    That is, the folder VB express puts them in. When I try the following code
    I get this:
    Cannot open database "Calendar.mdf" requested by the login. The login failed.
    Login failed for user 'HomePC\John'


    Dim conn As SqlClient.SqlConnection
    conn = New SqlClient.SqlConnection
    conn.ConnectionString = "Data Source=.\SQLExpress;Initial Catalog=Calendar.mdf;Integrated Security=True"

    Dim cmd As Data.SqlClient.SqlCommand
    cmd = New Data.SqlClient.SqlCommand
    cmd.CommandType = CommandType.Text
    cmd.CommandText = "Select ItemDate from Items"
    cmd.Connection = conn

    Dim ds As New Data.DataSet("Items")
    Dim da As New Data.SqlClient.SqlDataAdapter(cmd)
    da.Fill(ds)

    Thanks in advance for any help you can give me

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Problem with SQL Express connection string

    SQL Server (or SQL Express) isn't like Access, where you can just specify the file and be done with it. The database has to be attached to the server. Usualy this is in the management are of SQLExpress some where. Once it is attached and running, your connection string needs to be changed to point to the server (DataSource) and the Database NAME (Initial Catalog).... not the file name.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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