LightSwitch Beta 1 looking for SQL Express instead of full SQL instance - sql-server

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.

Related

Can MSSQLLocalDB be used on production web server?

Long story but I have a web app that has a SQL Server DB that works fine but also has a ASPNETDB.MDF database (for membership), which has always worked fine under SQL Server 2008. I did an upgrade on the server to SQL Server 2014 and I can no longer access the ASPNETDB.MDF database and get this error:
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 modified the connection string to update to what is expected with 2014 and that works fine in a simple console app (I can connect, run SQL commands, etc.) But I have not been able to figure out why I can make it work in production. NOTE: it doesn't even work in a browser on the web server - I get the same error.
Here is my connection string:
<add name="DefaultConnection" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|ASPNETDB.MDF;Trusted_Connection=Yes" />
I think it's possible... but really, you'll do much better installing Sql Server Express Edition on that machine, and then attaching the mdf file to the Express instance.
You'll also need some work to setup security and a few other things, but this puts you back into a more "normal" or typical deployment scenario for a web database. This will also make it much easier to troubleshoot the kind of error seen in the question.
It maybe your Remote Connection is not enabled on Server Side.
You have to make sure that it is enabled.
Here's you some guide1 and guide2 to make it Done

No data connection after cloning ASP MVC project to different computer

I was working on an ASP.NET MVC5 application and pushed it to git. Someone else cloned the project to their computer.
When they try to run the app it works up until there is a database call. They get the error message:
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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)'
In the Server Explorer we can see that the connection is closed. We also see no tables at all, like as if there was no database.
Does anyone know how we can approach this? I'd think that the connection string remains the same on each machine? The database was created code first, do we somehow have to recreate it? If so, how?
Thanks for your suggestions!
The connection string should be the same.
You should first disable Windows Firewall and antivirus programs (and similars), if they're present, and test again.
You should try a connection via another database client too, just to check if you are blocked someway.
If these attempts doesn't solve the problem, you can recreate the database for test pourposes, if you will. For Entity Framework, for example, search "migrations" term in Google.
The error is relevant. Obviously, from the computer hosting the cloned solution, the SQL server is not reachable.
If, in development, you used a local SQL Server (like SQL Express or Local DB), you must verify that on the computer hosting the clone solution you have the same setup. If you used a remote server, you must check that the server is available to the computer hosting the cloned solution.
In both cases, you can use Server Explorer to verify the db connection and access.
Unfortunately, there is no satisfying answer.
At first, we reinstalled Microsoft SQL Server. That alone did not help.
We did change the autentication from Windows Authentication to SQL, because the person working on that workstation still had the account details from the previous owner.
That alone did make the test connection successful. But then, we got another error when doing the "Update-Database" command in VS, which we solved by deleting a rogue migration that was there for some reason unknown.
Now it works - sorry for not offering a more concise solution.

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

Error while trying to connect to SQL Server - localhost

I have checked the instance name, auto close is set to true, allow remote connections on the server is checked. The server is running when I open the SQL Server configuration manager. I have even rebooted. I have created this db the same way as all others. I use Entity Framework and have checked the names in the web.config and they match. This is the default connection string from the wizard - I use for testing before I deploy. I just can't think of anything else to check to figure out why it won't connect. Working inside SQL Server everything is fine.
Here is the general error.
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)
Config:
connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string='data source=.\SQL_1;attachdbfilename="C:\Program Files (x86)\Microsoft SQL Server\MSSQL10_50.SQL_1\MSSQL\DATA\A_db.mdf";integrated security=True;connect timeout=10;user instance=True;multipleactiveresultsets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />
Thanks in advance.
Let me preface this answer by saying that proper setup of a SQL instance is not as easy as Microsoft would like you to think with the entity framework. It's a little bit involved and requires that you put your DBA hat on for a little bit.
The error you have indicates that the web instance is attempting to connect to the SQL server using Windows Integrated Security. This will work fine if (a) the windows user that the process is running as (which can be configured in IIS) is authorized to log on to the SQL server and has a valid login in the database and (b) if the SQL server is on the same machine or in the same domain as the IIS server.
In light of this, I recommend using SQL Server authentication. If you need to know how to do this, I recommend searching for "SQL Server Authentication setup" - here is an article that I found which might help you set this up.
http://msdn.microsoft.com/en-us/library/aa337562.aspx
In general, I recommend taking the following actions:
Connect to the sql server using MS SQL Management Studio.
Permanently attach your database, then use the Initial Catalog property on your connection string rather than AttachDbFileName
Then set up your login username and password on the SQL server, and create a login in the database for it.
Make sure your login can only execute the stored procedures you want it to execute. Deny it access to running sql statements.
You will also need to add the username and password to your connection string, and set IntegratedSecurity=false.
Let us know how things go once you get your SQL server set up properly.
This error means that your provider code cannot find the SQL Server. If you have checked the server instance name (it should be <yourLocalServer>\SQL_1), then it could be the attachdbfilename= parameter, as this is a really unreliable way to specify the database to connect to (you should be using the Database Name, not the file name), because there are about a hundred reasons that the file name could change that have nothing to do with your application.

SQL Server: "a connection was successfully established with server....existing connection was forcibly closed by the remote host."

Yes folks, it's this one again.
"A connection was successfully established with the server, but then
an error occurred during the login process (provider: TCP Provider,
error: 0 - An existing connection was forcibly closed by the remote
host.)"
I'm sorry... I have Google'd this, I have read the other StackOverflow articles on this problem, and I have tried all kinds of suggestions, but nothing works.
Here's a few notes about what we're seeing.
This issue occurs occassionally in SQL Server Management Studio itself (doing any kind of database activity... getting a list of tables in a database, having a look at a Stored Procedure, etc)
It also happens in Visual Studio 2010 itself, when it is trying to get data from the servers (e.g. when creating a .dbml file, etc)
It also sometimes happens in our .Net (ASP, WPF, Silverlight) applications.
Our SQL Server 2005 & 2008 servers are all based on virtual machines in data centres around the world, and we see sometimes this error on each of them. But most of the time, they all work absolutely fine.
When the error does occur, we can just "retry" what caused the error, and then it'll work fine.
We think.. if we have an IIS Web Server in a data centre in a particular city, and it accesses a SQL Server in the same data centre, then we don't see the issue.
We think.. if we connect to the servers, and specify the UserID and Password to use, it causes this error much more frequently than if we just use Active Directory authentication.
Put all that together, and it sounds to me like some kind of network issue.
But can anyone suggest what to look for ?
This isn't a bug in our .Net applications, as even SQL Server Management Studio "trips up" with this error.
It's baffling us.
Just in case anyone else hits this issue, we finally found the solution.
Our company uses Riverbed software to compress data, when it's being passed between locations, and this was somehow causing some connections to get dropped.
Our IT gurus found a configuration setting which finally fixed this issue.
I believe there's a setting in there to turn off compressing results from SQL Server (or something like that). That fixed it for us.
It could be any number of network issues. ANYTHING that prevents the code from reaching the server even for the few miliseconds it takes to make one query.
it could also be the result of a failover. When we went from a single SQL Server to a clustered environment, we'd see this happen during a failover. In this case, it turned out to be our Connection Pooling. In essence, the SQL cluster has a controller and two servers behind it. A and B.
Say our web app is using server A just fine, Connection pooling creates a connection on both sides. The server is aware of it, and the web app is aware of it. Once the cluster fails over to the second server, the web app is aware of the connection but server B is not, so we get an error.
The point is, any possible cause of network issues imaginable may be the cause. DOS attacks on the server, man-in-the middle attacks intercepting and changing traffic. Someone trips on an ethernet cable and it's loose in the jack. You name it, if it can cause a connection issue, it could be the cause.
Your issue also sounds like one we had recently - we also have a virtual environment, wih software that moves VMs from one host to another as needed for load balancing. Every so often, we'd get bombarded with the same error. It turned out to be an issue with the NIC drivers on one of the hosts, so whenever a VM moved to that particular host, errors would occur.
It's really not a programming issue. It's an environment issue, and you need trained professionals with direct access to your environment to research and resolve this.
My problem was that I was inadvertently using a wireless network to connect to our network because the Ethernet cable was faulty. This after repairing SQL Server, running a Winsock reset as recommended elsewhere ...
I am experiencing the same issue and our app interfaces with a several Azure SQL DBs. I believe (same as you) I do not have a bug in the C# code to cause this issue. We've solved it by a simple for loop containing an extra attempts to try to connect to the Azure SQL again if the previous attempt fails and then run the query.
Most of the time everything runs fine but sometimes we can see the loop kicked-in and on the 2nd or 3rd time it executed properly without the below mentioned error. After that we see in the log file the error below for all the unsuccessful attempts:
A connection was successfully established with the server,
but then an error occurred during the login process. (provider: TCP
Provider, error: 0 - An existing connection was forcibly closed by the
remote host.)
Even though this is a less-then-pretty solution, it allowed us to run our app without interruptions. I know you've mentioned that trying to connect again (to introduce some connection-failure tolerance) solves the problem and unfortunately this is the only correct solution I found so far as well.
I should mention that we have tried many debugging strategies to figure this out. Right now it all points to the availability of the database we are trying to connect to i.e.: It happens if the number of allowed DB connections is exceeded. (or so it seems at this time)
Turn off your VPN
My Problem fixed by turn off VPN
It was happening in our code when we were opening the dbconnection for oracle and were passing DBtype as SQL in our database object.
in my case - the error was Microsoft first suggestion:
Client is connecting with an unsupported version of the SQL Server Native Client.
In our case, We got this error when we updated sql server to sp3. We were not able to connect to the database from SSIS package.
We updated the native client and configurations. We were able to connect.
link to download the native client - https://www.microsoft.com/en-us/download/confirmation.aspx?id=50402
Link for configurations settings and further troubleshooting - https://learn.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/ms187005(v=sql.105)
Hope it helps.
Cheers!
Had the same type of issue. In my case it was a bit more complicated... I could connect to “ServerA” from “ServerB” via SSMS, but it would fail with sqlcmd. The error was the same:
Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : TCP Provider: An existing connection was forcibly closed by the remote host.
I could also connect from “ServerC” with both SSMS and sqlcmd. The following are the versions on the VMs:
ServerA: Microsoft Windows Server 2012 R2 Datacenter / Microsoft SQL Server 2012 (SP3-CU10) (KB4025925) - 11.0.6607.3 (X64)
ServerB: Microsoft Windows Server 2012 R2 Datacenter / Microsoft SQL Server 2012 - 11.0.5058.0 (X64)
ServerC: Microsoft Windows Server 2012 R2 Datacenter / Microsoft SQL Server 2012 (SP3-CU10) (KB4025925) - 11.0.6607.3 (X64)
Bottom line was the “unsupported version”. I noticed a mismatch of “sqlncli11.dll” between ServerC and ServerB, so I copied it to the System32 folder. After this, sqlcmd worked like a charm. Below were the versions in my case:
Failed:
FileVersion: 2011.0110.5058.00
ProductVersion: 11.0.5058.0
Worked:
FileVersion: 2011.0110.6607.03
ProductVersion: 11.0.6607.3
I was working on 2 projects at the same time (on 2 different machines) and both used SQL Server.
When i disconnected SQL with 1 machine the errorMessage went away. Probably you can mess around with IP-adresses too to fix the problem.
In my case I was seeing this error intermittently from a .Net application connecting to a SQL server located in the same server room. It turned out that some of the databases had auto close turned on which caused the server to close the connections in the pool. When the application tried to use one of the pool connections that had been closed, it would throw this error and I saw a log message on the SQL server that the database it was trying to connect to was being started. Auto-close has now been turned off on those databases and the error hasn't been seen since.
Also, having auto-close on is the default behavior for SQL Express databases and these were originally created on an Express instance during testing before being migrated to the production server where we were seeing the errors.
this answer is for those how have this problem with Azure Sql server database.
It happens when you reach mat pool
first remove Persist Security Info=False from connection string
second check your database plan in azure portal and increase the PTUs of your database plan.
In SSMS "Connect to Server" screen click Options, then on "Connection Properties" TAB change "Network protocol" to "Named Pipes"
Try this -
Click Start, point to All Programs, and click SQL Server Configuration Manager.
Click to expand SQL Server Network Configuration and then click Client Protocols.
Right-click the TCP/IP protocol and then click Enable.
Right-click the Named Pipes protocol and then click Enable.
Restart the SQL server service if prompted to do so.
I have had this issue a couple of time already, and I've fixed by reducing the MTU size. Often 1350, 1250, etc on my network interface.

Resources