LocalDB - Error 26 Network related issue - sql-server

I have a project created while running 2008r2 express and connecting to an instance named "Sqlexpress". I have recently uninstalled Sql server 2008r2 express and started using the recommended LocalDB. All of my projects updated the database successfully and connect flawlessly with the exception of one, my largest project.
The database updated perfectly but now i get a Error 26 - Network or instance related error each time i try to login in. (iterating through a dataset created in the dataset desinger.
Here is my connection string:
Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True
I can see the connection in Server Explorer and view table data. Any idea why this wouldn't work at runtime on this one project?

I solved this by opening Dataset.Designer.vb in notepad++ and replacing all instances of ".\SQLEXPRESS" with "(LocalDB\v11.0". I also had to set each instance of "User Instance=True" to False.

I solved the same by replacing the "(localdb)\v11.0" with applicable "MyServerName\SQLServerInstanceName" in connection string. During the installation of SQL Server Express 2014, I chose to keep SQLExpress as instance name.

Related

Where to find localdb created?

Currently I was going through Microsoft's ASP.NET Core MVC tutorial and it came to a point where I created a database context class, coming complete with a connection string that I add during the config.
Problem is however, when I check with SQL Server Management Studio, I cannot find the database created; I've logged on to both my local host as well as my PC name (for Windows auth) but the database created doesn't exist on either servers.
MS stated in their docs that when I run the command Update-Database in the PMC it would create it but I cant find it anywhere. I've tried using the name of the server from the connection string (localdb) but I cannot connect because SSMS doesn't recognize the instance.
Any idea why it doesn't show up on the studio but seems to work fine during the application running?
Connection string as follows:
"MvcMovieContext": "Server=(localdb)\\mssqllocaldb;Database=MvcMovieContext-1;Trusted_Connection=True;MultipleActiveResultSets=true"
About the LocalDB location, please, take a look here:
https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/sql-server-express-localdb?view=sql-server-ver15#:~:text=User%20database%20files%20are%20stored,add%20tables%20in%20Visual%20Studio.
Your LocalDB should be located on C:\Users\<user>\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\mssqllocaldb, assuming mssqllocaldb is your instance name, based on the connection strig you have provided.
Also, to connect to your LocalDB, follow the answers given on this post, I guess could be helpful on your case:
How to connect to LocalDB in Visual Studio Server Explorer?

Failed to retrieve data (SQL Server Authentication)

I am trying to connect to a database created in the SQL Server 2016 express edition, through Data Source Configuration Wizard in VS2017 Express edition, with SQL Server Authentication.
I created the user in SQL Server, and when I test the connection works perfectly, but vs displays the error. Also in Server properties, I set up SQL and Windows authentication.
I finally found a solution. I checked the checkbox remember password while creating connection string...and now can retrieve data for that user. In connection string is added persisted security=true. Still don't know why this need to be checked, because I follow example without persisted security, and there it worked, but on my PC didn't.

Connection to SQL server from VS DataSet designer not working

So, after the last weekend I have been having serious trouble connecting to an SQL database through the Visual Studio environment.
This is the enviroment
My OS is Windows 8.1 Enterprise
I'm running Visual Studio Community 2013, and develop in VB
The SQL server is located off site. The version is 12.0.2269. I do not administrate this one, but it is the back-end for the company ERP system so it is running on stable platforms and working well for hundreds of users.
In VS, I have a connection string set up under Project Settings:
Data Source=a.b.c.d;Initial Catalog=dbName;Persist Security Info=True;User ID=xxx;Password=yyy
(Connection uses ".NET Framework Data Provider for SQL Server")
This is what I have tried
The SQL server answers to ping
I can connect to the database through Microsoft SQL Server Management Studio 12.0.2000.8
In VS, under Project Settings, I can open the connection string configuration dialog. When I click "Test Connection" everything works fine (Test connection succeeded).
If I start the application I am developing it can connect to the database without problem.
BUT, if I go to the dataset designer, right click a TableAdapter and select Preview Data..., the application hangs for a while and then this error message comes up:
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server).
I should also mention that this worked before last weekend. I have not changed anything to the project. The only change I can see is several windows updates installed during the weekend.
This seems to affect only one particular project. Connections to the same database seems to work well in other solutions.
I have no idea what to do from here. Have this happened to anyone else?
My connection is like that and work, try with that:
Public Function FunctionConnection() As SqlConnection
FunctionConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\TCO_Orders.mdf;Integrated Security=True;User Instance=True")
'FunctionConnection = New SqlConnection("Data Source=;Initial Catalog=DATABASE;Persist Security Info=True;User ID=;Password=")
Return FunctionConnection
End Function

SQL Server 2012 connection string for EF5 Code First

I created an MVC4 solution in VS 2012 with EF5, and right now I am trying to get the database to be created Code First. In the Create method of the controller I added db.Database.CreateIfNotExists();
On my machine, I also have SQL Server 2012 running, and I would like the db to be created there instead of in some SQL Express engine or other lightweight solution.
I have tried several approaches to making a correct connection string, but all has failed, and now I have no idea as to how it should look. This is how it looks now, but nothing gets created, and all i get from the CreateIfNotExists is an error:
InnerException {"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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"} System.Exception {System.Data.SqlClient.SqlException}
This is what my connection string looks like:
<add name="Tool.Models.Context" connectionString="Server=MSSQLSERVER;Initial Catalog=Tool.models.ToolDb.mdf;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
EDIT:
After struggling with this issue for almost a day, I resolved it by substituting localhost for MSSQLSERVER (Which still is the name of the instance if I look at the Configuration Manager). Thanks for the comments though. Made me think.
localhost is the local server, not the instance, you appear to be using the default instance (called mssqlserver) and so don't need to specify the instance name, just the server name, hence why substituting MSSQLSERVER with localhost in your connection string works.
You could also use the actual name of the server in here, e.g. SERVER-01 (or whatever the actual name of your particular DB server is) and it would have the same effect.
If however you had installed a named instance on the machine, you would have to specify both the server name and the instance, e.g. localhost\instancename or server-01\instancename
Hope this helps explain why putting in localhost works.
That's right...
By default, as most may already be aware, Visual Studio 2012 - ASP.NET MVC 4 templates
will define a Default connectionString that points to a (LocalDb)v11.0 in Web.config.
In the case of Visual Studio 2010 ASP.Net MVC 4 project templates, it pointed to SQLExpress...
In my case I prefer pointing the connectionString to a specific SQL Server 2012 I use for dev.
So let's say I open SQL Management Studio and see SQLServer2012-01 name in a droplist where I want the database + tables to be created,
well that's the name I'd normally use...
connectionString="Server=SQLServer2012-01; InitialCatalog=..."
All you have to do afterwards is straightforward - follow the steps in defining
-Enable-Migrations
-[fill your Seed method with content - if needed...]
-Add-Migration MyFirstMigration [or any migration name you want]
-Update-Database -Verbose
and you should see results updated in Server Explorer Window.
Hope it helps

LightSwitch Beta 1 looking for SQL Express instead of full SQL instance

After resolving issues with RIA installation here, I'm still getting this following error. Not much special - I tried to create a new screen based off of data sources from an existing database in a full SQL 2005 instance
An error occurred while establishing a
connection to SQL Server instance
'.\SQLEXPRESS'. 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: 26 - Error Locating
Server/Instance Specified)
I've tried to correct the connection string in the, I guess, autogen'd config file. Even though Visual Studio doesn't seem to think that the file is overwritten on rebuild, the error continues to appear.
How can I use LightSwitch with full SQL 2005 rather than SQL Express?
It seems when working Locally, LightSwitch uses SQL Server Express. It puts it's Membership, Roles, and other authentication information here. I don't know any way to get around this locally, but when you go to "Publish" your project, you're given the ability to use a different database/server. You can also use whatever server/database you'd like for your data sources as well.
Hopefully, before V1, they'll allow you to change that. But I haven't found a way yet, without the config being overwritten constantly.
You can't use it with non Express version during development when you want to use LightSwitch to create your data model. If you deploy your project, as mentioned, you can use the created database with full version and change the connection string.
Although I would be cautious using SQL Server 2005 because LightSwitch is using datetime2 which is new in 2008. (maybe some more 2008 specifics as well)
http://lajak.wordpress.com/2011/10/04/lightswitch-change-default-database-instance/
Here, they are telling how to change instance name both in project level and global level.

Resources