Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005
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;"
 

Anyone that knows anything about this, that has tried it him self?
Posted 19-Feb-13 21:06pm
Edited 19-Feb-13 22:55pm
v3
Comments
NaVeN Kumar at 20-Feb-13 3:12am
   
Did not understand...Can you please elaborate your question...?
pluss400 at 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 at 20-Feb-13 3:33am
   
could'nt understands ur query. what u want actually? connection string or what?
pluss400 at 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 at 20-Feb-13 3:46am
   
please ur .net version. in which version u r making app? may be ur software will be crashed
pluss400 at 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
good
Please Sign up or sign in to vote.

Solution 1

Look over here for an example of many types of connection strings.
 
http://connectionstrings.com/sql-server-2005[^]
 
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.
  Permalink  
Comments
pluss400 at 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
0 OriginalGriff 405
1 Sergey Alexandrovich Kryukov 220
2 Maciej Los 195
3 Peter Leow 190
4 DamithSL 174


Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid