ConnectionString for VisualStudio-style SQL Server Databases

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If I create a database or attach a database file in the version of SQLServer
that comes built-in to Visual Studio, the ConnectionString that VisualStudio
automatically creates for connection to this database is a "file-based"
connection ("AttachDbFileName=...").

Is there a way to attach a database to this version of SQL Server that can
be connected to from my development code using the "Server=...; Initial
Catalog=...;" approach instead? This would make it a lot easier to test if
everything is working as it should.

Alex
 
Alex,

In the version 2.0 you can always add a partial class to a class to get what
you want.

Cor
 
You lost me. A "partial class" to what? I'm talking about how I connect to a
SQL Server database. I must be missing something.

Thanks.

Alex
 
Yes, you can. The problem is that when you build a project that contains the
database file, Visual Studio works with SQL Server Express to create a user
instance where the database is temporarily attached. The process is kinda
convoluted but if you have Visual Studio Standard or Professional, you can
take the .MDF file generated by Visual Studio, copy it to a convenient
location (outside of your project directories) and use the Server Explorer
to attach it to a specific instance of SQL Server. After that your
connection string would look something like this:
"Data Source=MyMachine\SQLEXPRESS;initial catalog=MyDatabase;integrated
security=SSPI"


--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Alex,

I am assuming that you created the connection string with a wizard. That
creates as it is a windowform, either in C++, Net or VB for .Net a Class.
You can see that in your solution explorer as you click on show all files in
top of the solution explorer. In that class is the entree to your connection
string. I thought you could get it direct, so probably that partial class is
not needed. However in version 2005 you can always extend a class with a
partial class.

Cor
 
Back
Top