Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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
Updated 19-Feb-13 22:55pm
v3
Comments
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.
mahi0607 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.
mahi0607 20-Feb-13 3:46am    
please ur .net version. in which version u r making app? may be ur software will be crashed

1 solution

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.
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900