Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a database programmatically in a vb.net winform project. I am wondering what is the connection string I use? The one I used up to now has been:


VB
connectionString = "Data Source=.\SQLExpress;Initial Catalog=Master;Integrated Security=True;MultipleActiveResultSets=True"



This has worked because before I had the database already created in SQL Server 2008 express, so I was just connecting to the database that was there using the above connection string. Initially when I created the project, it would connect to the database and use the database accordingly, but now I want to create the database programmatically first in the project and then let it do what it's supposed to do. Should I be changing the connection string and if so, what should I change it to, to do this?
Posted

1 solution

Change the "Initial Catalog" from "Master" to the name for your new Database.
 
Share this answer
 
Comments
Member 10804519 7-Aug-14 10:45am    
That won't work, I need the connection string to connect to SQL Server when the database isn't created. I can't replace 'Master' with my new database if the database doesn't exist.
OriginalGriff 7-Aug-14 10:56am    
Then you need to tell us exactly what you are trying to do when you ask a question! :laugh:
Remove the "initial catalog" part completely and it should just connect. Then provided you have suitable permissions, you can just create the DB.
Member 10804519 7-Aug-14 11:28am    
Do I leave the 'Initial Catalog=myDatabase' part in the connection string where I am creating the tables for the database?
OriginalGriff 7-Aug-14 11:38am    
Yes - or use the "USE databasename" command in your cretae table query
Member 10804519 7-Aug-14 12:06pm    
Thank you very much. I understand now and you've helped me a lot.

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