I have created a c# visual studio application that uses SQL LocalDB 2016 for its database. Visual studio only allows 2012 to be used as a prerequisite, but I was able to find a 2016 download online. I have tried both SQL LocalDB 2016 and 2017, but get the same error for both.
A network related or instance specific error occurred while establishing a connection to SQL Server. Ther 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. ... error 50...Cannot create an automatic instance.
I have ran sqllocaldb i on cmd and the result was MSSQLLocalDB which is the automatic instance for SQL LocalDB. The connection string in visual studio is set up for MSSQLLocalDB. I have uninstalled all other versions. The only thing I can think of that could be causing a problem is permissions. Thanks
Related
I have created a C# project using VS 2019 which connects to LocalDb.
Any machine which has 64 bit, I install SQL Server 2016 LocalDb before running my project and after that it works fine.
Now some machines are using 32 bit operating system, so I installed SQL Server 2012 Express LocalDB.
But my project is not working and I get this error:
System.Data.SqlClient.SqlException: "A network or specific instance error occurred while establishing a connection to SQL Server. The server could not be found or is unavailable. Make sure the instance name is correct and that remote connections are allowed on SQL Server. (Provider : SQL Network Interfaces, error: 50 - A Local Database Runtime error occurred. An unexpected error occurred while calling the LocalDB instance API method. For more information about the error, see the Windows Application Event Log.
This is my connection string:
Server=(LocalDB)\MSSQLLocalDB;Integrated Security=true;AttachDbFileName=D:\Data\TestDB.mdf
Any help would be appreciated.
Thanks
I'm following [this tutorial], I'm trying to create EF database in C# console application, but (even if I do exactly everything as in tutorial) it fails on
db.Blogs.Add(blog);
db.SaveChanges();
lines. Error:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in EntityFramework.dll. Additional information: 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: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)
As author of tutorial says, it shouldn't require me to do anything to configure my DB, but it seems like it does.
What should I do to make it work?
Software that I use:
Visual Studio 2015, EntityFramework 6.1.3.
In Visual Studio 2015 the built in SQL database the comes with it is mssqllocaldb and not SQL Express.
This can be accessed with:
(localdb)\MSSQLLocalDB
rather than
.\sqlexpress
In the tutorial under the section after "You can connect to this database using Server Explorer in Visual Studio" follow the instructions to connect to a database and replace .\sqlexpress with (localdb)\MSSQLocalDB if you can connect this database then change your connection string in your application.
The solution that worked for me is:
Open Visual Studio installer (*.exe file used to install Visual Studio)
Click on "Modify" button
Find "Microsoft SQL Server Data Tools" and check it
Click "Update"
Now your database should work.
I have SQL Server 2014 installed and want to use localdb\v12.0 in Visual Studio. I found this post and understand how to connect to localdb using SQL Server Object Explorer successfully. Now I have created a LightSwitch project in Visual Studio 2013 and when building it throws exception:
An error occured while establishing a connection to SQL Server
instance '(LocalDB)\v11.0'.
Seems it is looking for SQL Server 2012 to create the development database in Bin\Data and I don't have SQL Server 2012 so there is no localdb\v11.0 on the system. So
Why does VS 2013 try to use localdb\v11.0?
How can I force Visual Studio to use localdb\v12.0 when building the project?
I tried changing the _IntrinsicData connection string in web.config but when building again it throws the same exception trying to use localdb\v11.0 which belongs to SQL Server 2012!
Ok after spending lots of time I found what was the problem! Here is the cause and solution:
LightSwitch uses SQL Express LocalDB to store information such as User and Roles when building the project (this is called development database). There is no problem with SQL Server 2012 but if SQL Server 2014 is installed something force the LightSwitch to connect to (localdb)\v11.0 . LightSwitch makes three projects in the solution. If the Client and the Server projects build successfully so the problem is with the third project. Go through these steps:
Right-Click on the third project in the solution
Select Unload Project
Again Right-Click on it and select Edit <yourProjectName>.lsxtproj
Search the SqlExpressInstancename
You will find its value is (localDB)\v11.0 !
Change it to the right SQL Server LocalDB instance name; for more information check the notes below
Now the solution successfully build
--
Note 1: To see which version of SQL Server LocalDb is installed, open cmd and type sqllocaldb.exe v
Note 2: To which instance of LocalDb has been created on the system, open cmd and type sqllocaldb.exe info
Note 3: The instance which is going to be used by LightSwitch must be started: open cmd and type sqllocaldb.exe start
UPDATE: Looking for a better solution I found the correct way to fix this problem. It was a pain for me to follow those 6 steps every time I create a new LightSwitch project. So if you want to fix it once you can do it this way:
In Visual Studio go to Tools->Options
In the Database Tools select the Data Connections
Set your desired SQL Server Instance Name
So no need to set it every time you create a LS project
I'm trying to create a SQL Server database from Visual Studio Database Explorer. When I right click on Data Connections, the Create New SQL Server Database option remains grayed out.
I have VS Express 2012 and SQL Server Express 2012 installed in my system. SQL Server instance is up and running.
Do I need to configure anything, so that Visual Studio recognizes the installed SQL Server instance?
You first need to make a connection to the SQL Server before you can create a database.
Click the Add Connection option and connect to your SQL Server instance, then the option will become available on your connected Server.
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...