What does localsql mean in connection string? - sql-server

I am in the process of migrating sites from server A to server B, in the connection string, data source of some of the sites in server A, it says localsql but there is no ssms on server A because of which I am unable to find any databases on server A.
More interestingly, I have moved one site with localsql in the connection string to server B and the site is still working as expected.
I want to make sure there are no databases on server A and I want to know what exactly does localsql means in this context.
Any help would be appreciated.
Edit: Adding connection string
<appSettings>
<add key="ConnectionString" value="Data Source=localsql; Initial Catalog=dbname; User ID=id; Password=pw" />
</appSettings>

Probably the site hosted with LocalDB (named instance) which is light version of SQL Engine runs without a service. Usually, this can be identified by looking at connection string (which directly pointing the .mdf file) as it's different than regular SQL Server connection strings.
If it's localdb, these steps might be helpful to migrate the .mdf to SQL Server.

Related

Issue with website deployed to IIS and connecting to SQL Server 2012, getting network not found error

I have deployed a website to IIS and it is trying to access the database via the connection string.
My SQL Server and connection string is correct as I have tested it in the following ways:
My development environment streams data correctly
Connection to SQL Server is good as I could see from SQL Server Management Studio
Other pages of the website that are deployed are correct and only those pages that stream data is failing.
The problem is that it is only through the IIS website we have this error and when I run it from Visual Studio it is all right.
Here is the stack code I get:
Stack trace error
My connection string:
<add name="cnnSQLDB"
connectionString="server=**********;database=*********;Integrated Security=True;User ID=******;Password=******;"
providerName="System.Data.SqlClient"/>
Make sure that port 1433 is open on your firewall. That is the port SQL Server uses.
I was able to solve this issue based on hints provided here. I had to do the following changes:
Update the SQL connection string and set "Integrated security=false". In that way it will use the login credentials provided in the SQL connection string.
Create a new user as provided in the SQL connection string and GRANT the necessary accesses.
When I copied the databases from the production environment to a new environment the GRANT permissions for the user mentioned in the connection string was not updated.
But by checking the port status via the command 'sp_readerrorlog' gave me clues and led me to a solution. Some other links that helped me were: this and this

entity framework database issue - A network-related or instance-specific error occurred while establishing a connection to SQL Server

A network-related or instance-specific error occurred while establishing a connection to SQL Server
The main page loads fine, but the error occurs when I try to goto Account/Register or Account/Login.
The error occurs on this line in SimpleMembershipInitializer constructor in file Filters/InitializeSimpleMembershipAttribute.cs
if (!context.Database.Exists())
Now, if I set my web.config to
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework" />
</entityFramework>
it works locally only but I'm assuming it's using a local database. Right now my entity framework in the web.config looks like
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
I have another application where I am using the same hosting service and free database (appharbor and SQL Server Yocto) and it works just fine. I recently setup a new application and database and it doesn't work. I can connect to the database fine in SQL server and expanding the DataConnections -> MyContextName in visual studio 2012, so I know the connection string is not the problem.
I'm wondering if there is a problem on the server the database is hosted on and I don't have access to that.
I'm all out of ideas on how to fix this problem. Thanks.
The problem probably is that the connection string name hasn't been configured properly and/or doesn't follow the entity framework conventions (which differs a bit between Entity framework versions). If you can connect to the database from your own machine or from the SQL server admin page the problem is unlikely to be related to the database/database server itself.
Take a look at this discussion where another user experienced a similar issue. You might just need to set the right connection string name for the entity framework database context. Also make sure you have migrations set up to create the database.
This may explain why it's working locally with the local db connection factory. I suspect that a database is created in your local SQL server, and it can do so unrestricted. On AppHarbor you need to use the database and connection string provided since you can't create databases yourself. You can confirm whether that's the case by connecting to your local database server and listing the available databases.
I can also recommend using this sample application and the associated blog posts about running migrations and configuring entity framework (4.3) on AppHarbor.

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

Cannot create a local sql server 2012

I am trying to create a database for an MVC 4 application. I used Entity Framework Code first approach. After digging into the problem I realized that it was not a connection string issue. I downloaded Sql Server Data tools and tried to create it from there but I get the same exact error which is related to Windows Authentication. I am not sure what is causing this problem, I even tried running as admin.
Any ideas??
I have tried mostly all forms of connections strings available online, the last two that I tried were
<add name="Request" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=Requests;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\Requests.mdf" providerName="System.Data.SqlClient" />
<!--<add name="RequestsContext" providerName="System.Data.SqlServerCe.4.0" connectionString="Data Source=|DataDirectory|\Requests.mdf" /> -->
I am trying to create a local database, I have asked a question about entity frame work right here thinking that the problem was from there but now I know it has nothing to do with it. Here you can see all of the details about the models I created and I am trying to generate the database from.
Using Entity framework with SQL Server 2012 (local *.mdf database)
You don't have SQL Server installed on your PC. Install Express Edition and you should be fine.
EDIT: Use connection string for local server:
<add name="Request" providerName="System.Data.SqlClient" connectionString="Server=.\SQLEXPRESS;Database=Request;Integrated Security=True;" />
If its local, probably SQL Server service is not running. Start>cmd and services.msc will open services page. Right click on sql server and start

Network-related error in SQL Server

the following error appears when I want to launch the Security tab in ASP .NET Configuration site for my ASP NET MVC 4 project:
http://s14.postimg.org/jvizqragv/error_sql.png
I know that there are a lot of questions related to that error, but i tried a lot of the tips for solving this (I tried the suggested solutions here - http://blogs.msdn.com/b/walzenbach/archive/2010/04/14/how-to-enable-remote-connections-in-sql-server-2008.aspx but the error is still here).
But let me explain what are my databases in the solution. I have a local database (an .MDF file in App_Data) and a database for users authentication which was generated by ASP NET MVC. They are all placed in the App_Data folder as I'm trying to work on this solution on different machines. The strange thing is that on my laptop at home there is no such problem - I am able to create roles, explore users and all the functionality in the Security tab and I think there might be some problem with the SQL Server on my desktop machine - I use the Express edition on my laptop and the Developer edition on the other machine where things don't work.
My connection strings are the following:
<add name="FootballTransfers20130717145140Context" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\FootballTransfers.mdf;Integrated Security=True;MultipleActiveResultSets=True;Connect Timeout=30"
providerName="System.Data.SqlClient" />
<add name="DefaultConnection" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\DefaultConnection.mdf;Integrated Security=True;MultipleActiveResultSets=True;Connect Timeout=30"
providerName="System.Data.SqlClient" />
The first one is for the Entity framework and is related to the database where I store my application specific data. The second one is for the users administration database generated by SQL. Without the second connection string I'm not able to open any action of the Account controller.
It's very strange because it works on one machine and not on another. I was wondering if there's something wrong with the connection string, but I guess there's something with the SQL Server. As I said I tried various solutions but they didn't work.
LocalDB is a feature of SQL Server Express only. You will have to install SQL Server Express on the machine or import your database to your SQL Server and change your connection strings.
In production, you would probably have to move to a full SQL Server edition anyway.
I added the roles i was trying to make in code in the AccountController and now I'm able to register users with roles, but the problem that appeared now is that when I put the Authorize attribute on some action so that only users with certain roles can request them, the following error appears:
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)
When I remove the attribute so anyone can access it, the action works fine. I found some article on the net saying that providers must be specified in the config, but some errors kept appearing that those tags are unknown.

Resources