Reputation: 65
I am trying to learn C# and then I hit this roadblock. My Visual Studio 2010 wont let me create a service based database (the .mdf file). (Add>New Item>Service-Based Database)
Everytime I try to add new .mdf it would bring up an error.
A network-related or instance-specific error occurred while establishing a connection to the SQL server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
I can create a Local Database (Add>New Item>Local Database) without any problem, but I cant create .mdf
I am running on Windows 7 64bit OS and Visual Studio 2010 (Ultimate).
Upvotes: 0
Views: 9459
Reputation: 49
To temporarily attach a database file (.mdf) from the Data Connections node
Upvotes: 0
Reputation: 159
You can try
Check SqlLocalDB by
Sqllocaldb.exe i
You will see version number like (v11.0) otherwise complete the installation.
Create the sqldb by
sqllocaldb c dbname
You will see like "LocalDB instance "dbname" created with version 11.0."
Then Start the Db
sqllocaldb s dbname
You will see like "LocalDB instance "dbname" started"
See the created Db info
sqllocaldb.exe i dbname
Now try to create service-based database in c#.
Upvotes: 0
Reputation: 84835
Basic requirements for using these two kinds of databases:
Local Database (.sdf
): requires SQL Server Compact. That is, you need only an additional DLL, but no special system service. (If you know SQLite: SQL Server Compact is conceptually the same thing, only more powerful and feature-complete.)
Service-Based Database (.mdf
& .ldf
log/journal file): requires a running instance of SQL Server or SQL Server Express, both of which are standalone products (as Tim Copenhaver points out in his answer). For development purposes, you'd typically install one of these products on your development machine.
Likely cause of your problem: Guessing from the error message that you posted, you do not have SQL Server, nor SQL Server Express, installed. However, an instance of one of these products is required so that you can "attach" your database to it. This is required in order before you can actually access the .mdf
database.
To see whether you have SQL Server installed, you could e.g. open Control Panel → Administrative Tools → Services, and look out for a system service named "SQL Server (.\SQLEXPRESS
)", or "SQL Server (YOURCOMPUTERNAME\MSSQLSERVER
)", or similar. The name in the brackets is the name of the database instance running on your machine. SQLEXPRESS
is the default instance name for SQL Server Express, while MSSQLSERVER
is the default instance name for the full version of SQL Server.
If you do not have SQL Server installed, you can download e.g. SQL Server 2012 Express or SQL Server 2008 R2 Express with SP2 for free from Microsoft.
Upvotes: 1
Reputation: 3302
A service-based database needs to connect to a SQL Server instance. It's not built into Visual Studio, it's a separate application which needs to be running somewhere for you to connect to. That error message is basically telling you it can't find the SQL Server instance you're trying to connect to.
Local Database works correctly because it keeps everything local to your application and doesn't require an external database server to function.
Upvotes: 1