Hi.
Problem:
Cant rely find any info on this question. Maybe because it so easy?
I want to create my database and use it. I use SQLEXPRESS server 2005.
Question:
First time I do CREATE DATABASE I need a connection to the server to create my.mdf and my.ldf before I can use them.
My string looks like this and works fine.
"Server = .\SqlExpress; Database = master; Integrated Security = SSPI"
Next time I want to connect to my.mdf I cant get a connection to work. Howe should the string look like?
I have tried this and it dos not work.
"Server =.\SqlExpress; AttachDBFilename = my.mdf; User Instance = True; Integrated Security = True;"

I want a connection like this one
"Server = .\SqlExpress; Database = master; Integrated Security = SSPI"
that connects to my.mdf after i created my database
i tryed a lot of different settings and not any works. i obviously do something wrong.

1 solution

Solution 1

But typically when after you do your CREATE DATABASE call then you can just change the Database=master to the name of the database you created. Not with the extension, because the database has already been created on that server. If you wanted to tell a different server to attach to your external files, then the AddDBFilename would work. Take a look at the website. It is a great reference for these things.