Click here to Skip to main content
13,199,852 members (70,026 online)
Rate this:
Please Sign up or sign in to vote.
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.
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;"

Anyone that knows anything about this, that has tried it him self?
Posted 19-Feb-13 21:06pm
Updated 19-Feb-13 22:55pm
NaVeN Kumar 20-Feb-13 3:12am
Did not understand...Can you please elaborate your question...?
pluss400 20-Feb-13 3:23am
there happen something before i could finish my question.
it is fully readable now.
thank you fore looking.
mahi_p 20-Feb-13 3:33am
could'nt understands ur query. what u want actually? connection string or what?
pluss400 20-Feb-13 3:40am
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.
mahi_p 20-Feb-13 3:46am
please ur .net version. in which version u r making app? may be ur software will be crashed
pluss400 20-Feb-13 3:55am
C# .NET version 4.0 visual studio 2010
I have tried this
"Server =.\SqlExpress; AttachDBFilename = my.mdf; User Instance = True; Integrated Security = True;"

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Look over here for an example of many types of connection strings.[^]

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.
pluss400 21-Feb-13 6:11am
I´ve tryed it out and it works perfect.
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.171020.1 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100