|
-
Dec 14th, 2005, 10:35 PM
#1
Thread Starter
New Member
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
-
Dec 14th, 2005, 11:22 PM
#2
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|