Cant create service based database in Visual Studio 2010 - c#

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).

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.

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.

You can try
Go to Command Prompt from Start->Run(type cmd -> press enter)
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#.

To temporarily attach a database file (.mdf) from the Data Connections node
In Server Explorer, open the short cut menu for Data Connections and choose Add Connection.
The Add Connection dialogue box appears.
Choose the Change button.
The Change Data Source dialogue box appears.
Select Microsoft SQL Server Database File and choose the OK button.
The Add Connection dialogue box reappears, with Microsoft SQL Server Database File (SqlClient) shown in the Data source text box.
Choose the Browse button and browse to an existing .mdf file.
If you type a file name that does not exist, a blank .mdf file will be created.
Select either Use Windows Authentication or Use SQL Server Authentication.
For more information on SQL Server database access authentication, see Create New SQL Server Database Dialogue Box.
Choose the OK button.
The database appears in Server Explorer.

Related

What do I need to include SQL Server Express in my Wizard installation?

I've just finished a project with a SQL Serer database, so in my launch project I use this connection string
Data Source=(local);Integrated Security=True
And I check every time if database exists locally; if not, I execute a script to create the database and tables ... it works 100% without any problems.
But now I want to publish my project in Advanced Installer.. but when I try to install it on another PC, there was a error that said that I can't query database cause server is missing ...
I need the minimum prerequisite to add it in wizard installation, I've tried SQL Server 2005 Express, but it is still not working, the same error ...
Help me please ...
NB : I'm working with SQL Server 2014
You seem to have an unnamed default instance on your development PC so that you can connect to it using data source=(local).
When SQL Server Express is installed, by default, it uses a named instance of SQLEXPRESS, so your connection string should have
data source=(local)\SQLEXRPESS;....
in it, to connect to the SQLEXPRESS instance.
Or you need to change your SQL Server Express installation to install as the default, unnamed instance, too.

SQL Server error: 50 when trying to add .mdf file to App_Data

I was creating a web site project in Visual Studio 2015, created an App_Data folder and tried to add a SQL Server database file.
This error occurred:
A network-related or instance-specific error occurred while establishing a connection to 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: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.
I am using Microsoft SQL Server 2014 (v12.0). I checked the connection in SQL Server Configuration Manager, the server connection is enabled, my TCP/IP port is set to 1443, my Firewall is set for the connection as well.
I am able to connect to my server from Visual Studio Tools/Connect to Database Option, it's able to connect either to my server or to a local database. When I test my connection from there, it works.
I also see the connection is enabled and running from server explorer, and when I drag and drop an SQL DataSource Wizard from my ToolBox to an aspx page, the wizard sees the database and is ready to import it as well.
I also have tried double checking the connection under services.msc from cmd and it's all up and running.
Yet, when I want to right click and add a SQL Server database file to my App_Data folder, this error comes up.
I have no idea what is wrong.
Try to use (localdb)\mssqllocaldb as server name to connect to the LocalDB automatic instance. for more information read this article: http://www.sqlcoffee.com/SQLServer2014_0010.htm
Just for documentation (and SQL Express users having the same problems)
1. Check that SQL Express (master-) database exists and is reachable
In Server Explorer => Data Connections => Add Connection
(LocalDb)\mssqllocaldb
(LocalDb)\v12.0
(LocalDb)\v11.0
For further SQL Express problems see:
SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance
2. Configure Default Connection in Visual Studio
If you upgraded SQL Express the wrong connection string still resides in the VS configuration
Tools => Options => Databas Tools => Data Connections -> "(LocalDB)\mssqllocaldb"

Is it a must to install ms sql server 2005 separately to use in ms visual studio

In the past I used to install Ms SQL 2005 in my system separately but in recent years I never care to use them anymore as I totally depend on XML tables rather than those of Ms SQL. So I never had the need for installing them.
Today, I thought of trying out using Ms SQL 2005 again in my ASP.NET project as many people suggest that its far more better than XML tables.
When installing Ms Visual Studio 2008 Professional Edition, it seems some controls of Ms SQL 2005 is included. What I could see from the "All Programs" (from start menu) is the Microsoft SQL Server 2005 Folder. Inside, I have Configuration Folder only.
Now on my Visual Studio Project, My "Server Explorer" looks like the image below.
I cannot create a database by right-clicking the Data Connection. I always get an error same as the one I get when trying to add "New connection" by clicking on "Add Connection".
Let me show you how I did using images:
Step 1: Choosing the Data Source
Q 1: Are the data source shown here are installed on my system or just the names shown by Default even if its not installed?
Step 2: Connecting to Microsoft SQL Server
The Error says: "A network-related or instance-specific error occurred while establishing a connection to 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. (provide: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
Q 2: What does this mean?
My suspicion is that, this error occurred because I don't have SQL Server and my problem will be solved once I install SQL Server.
My curiosity is that, if SQL Server Database can be used even without installing SQL Server separately then why not just use it from here (Visual Studio) as some features seems to be already installed while installing Visual Studio.
Thank you for your time for caring to help me
Q1: That list does not show existing datasources, it shows available ADO.Net providers (you can think of them as database drivers).
Q2: Why did you enter "Me" as server name; is this the name of your computer? Try ".", "localhost" or "localhost\SQLEXPRESS" instead.
If you want to connect to SQL Server on your local machine, it needs to be installed on your local machine. The features installed as part of visual studio are front end management tools (depending on the version of Visual Studio installed).
Also, check out the version of SQL Server you're using for supportability purposes.
http://www.microsoft.com/en-us/sqlserver/support/support-updates.aspx
Those data sources shown in the image in Step 1 are not specific sources, they are simply types of sources. The Add Connection dialog you're looking at allows you to create a connection to, in the case that you selected Microsoft SQL Server, any MS SQL server you have access to connect to. Thus, your exact question: yes, what VS installs are simply drivers to connect to various databases, not the actual databases themselves.
Since you aren't running a MSSQL Server on your local machine, it tries to connect to your local machine to find a MSSQL server, can't, and thus gives that message. If you want to connect to a MSSQL server without installing one on your local machine, you could always find one someone else had installed on their machine and see if you could use it...

Modify app.config to connect to a database file in computer with no SQL Server Management Studio installed

I created a software using .net4 which uses ORM and connects to database. So when I need to connect to a file I have to first open SQL Server Management Studio and attach the database to it and then I am able to use my software if I don't do this it throws an exception that the underlying provider failed to open.
Now I want to deploy the software to my brothers computer who doesn't have Visual Basic and SQL Server installed on his computer (but he has the .net framework) so is there a way I can modify my app.config to point to the database file instead and I don't need to attach the file to the SQL Server?
Simply I don't want to attach or detach the file to the database again and again how can the .net automatically attach it.
Indeed, install the SQL Server 2012 Express LocalDB (it is likely already installed with your Visual Studio 2012 installation) and then modify the connection string as follows:
connectionstring="data source=(LocalDB)\v11.0;attachdbfilename=c:\MyDatabaseFile.mdf;integrated security=True;"
the (LocalDB)\v11.0 part is where you point at the LocalDB "instance", and you can attach any mdf file you want. Keep in mind that this locks up the mdf file, so you cannot have it open in Management Studio and run your app.
You mentioned attaching a database, but not wanting to install SQL Server. I would take a look at the SQL Server Express LocalDB. While it is technically installed, it is not installed as a Windows Service, so it is much lighter than full SQL server or SQL Express.

Visual Studio 2010 SQL Developement Server stopped working

I was making minor modifications to a view in my ASP.NET MVC 3 C# application when all of a sudden the application would no longer run. The error message is as follows:
System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to 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: Shared Memory Provider, error: 40 - Could not open a connection to SQL Server)
Upon close inspection of the server explorer I noticed that all database connections are no longer working. I cannot expand any of the connections to view the tables and data I previously generated within. When I attempt to, there is a pop-up window that is generated that repeats the exact same error as above.
It is important to note that I was not making any modifications to any portion of the application that pertains to a database. I was rearranging some of the visual components of a view in my application when all of this occurred. I had just recently restarted my computer and had made no other modifications since that time.
At first I thought that somehow SQL Express had overwritten my development environments version of SQL Server and began to reinstall SQL Server Express. The installation fails every time now. There is no specific error. Windows generates an error message saying that the setup application "stopped working" and hangs until closed.
I have tried several different versions of the SQL Server Express installation package, and they all result in the same error happening at different points in the installation process. To be clear, I'm not even sure SQL Server Express is the problem. I don't know why it would be since I'm using the SQL Server edition that is built into Visual Studio 2010.
Is the SQL service running? Check under SQL Server Configuration Manager.
Yes, another life saved.
Run-sqlservermanager11.msc, right click and start.
Is the SQL service running? Check under the SQL Server Configuration Manager.
I assume you've already tried to repair install, to uninstall and to restart your computer, pray then try again?
Are you databases remotely deployed? Because it is possible that the network is down.
Secondly, check in the we.config file if you have specified the correct credentials. Try to log in through SQL Server Management Studio.
One more thing: Stop the SQL Server service, and start it again. Or you can reboot the system.

Categories

Resources