SQL Server Express 2008 Connection Error (26) - asp.net

So I have few ASP.NET apps all running off SQL Server Express 2008 and working fine and dandy. I just put up a new one to test something and am now getting the Error 26 - can't find instance. What's weird is that the app is talking to the DB partially because it brings up the user login page and if I enter wrong data it returns a message about that (which is good). When I enter the correct login info it takes it then thinks for a few seconds and then throws the Error 26.
Here is my connection string --
<connectionStrings>
<add name="db_BPEntities" connectionString="metadata=res://*/App_Code.Data.db_BP.csdl|res://*/App_Code.Data.db_BP.ssdl|res://*/App_Code.Data.db_BP.msl;provider=System.Data.SqlClient;provider connection string="data source=LOCALHOST\SQLEXPRESS;initial catalog=db_BC_Build;user id=USER;password=PASSWORD;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="Default" connectionString="server=LOCALHOST\SQLEXPRESS;database=db_BC_Build;USER ID=USER;password=PASSWORD;Min Pool Size=10;Max Pool Size=800;Network Library=dbmssocn" providerName="System.Data.SqlClient" />
</connectionStrings>
Note: I've changed user/password info. The DB is running locally off the same box with IIS (it's a test intranet site so I'm ok with that for now).
So summary:
Other apps running off same DB have zero connectivity issues. They all connect and work fine.
This app partially works but on login throws the Error 26 - Instance not found.
Would it be that there are 2 connection strings here vs 1 connection string on my other DBs?
Really stumped.
Thanks for any/all help :)
Edit: I think the issue is with the Entity Framework and SQL Server Express. It seems to connect initially to authenticate the user, but then the EF connectivity to display data, etc is where it breaks. That's where I'm at right now and stuck in trying to figure this out (I didn't develop this application).

Try to connect without "Network Library=dbmssocn" in your connectionstring. I have had the same (error 26) issue and it did work for me.

I change app config file to this
<connectionStrings>
<!-- TLPL_ICT_OPR\MSSQLSERVER1;Initial Catalog=FMS;User ID=fms -->
<add name="DBConnectionString" connectionString="user id=fms;data source=TLPL_ICT_OPR\MSSQLSER;persist security info=True;initial catalog=username;password=password" providerName="System.Data.SqlClient"/>
<!--<add name="DBConnectionString" connectionString="user id=fms;data source=TLPL_ICT_PHOLIB\SQLEXPRESS;persist security info=True;initial catalog=FMS;password=fms4321"
providerName="System.Data.SqlClient" />-->
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
after this it works fine....

To quote from SQL Network Interfaces, error: 26, these are the steps to overcome this issue:
Make sure your server name is correct, e.g., no typo on the name.
Make sure your instance name is correct and there is actually
such an instance on your target machine. [Update: Some application
converts \\ to \. If you are not sure about your application, please
try both Server\Instance and Server\\Instance in your connection
string]
Make sure the server machine is reachable, e.g, DNS can be
resolve correctly, you are able to ping the server (not always
true).
Make sure SQL Browser service is running on the server.
If firewall is enabled on the server, you need to put
sqlbrowser.exe and/or UDP port 1434 into exception.
Please visit the link for more detail.

Related

Connectionstring doesn't work for Azure

I've been looking for this and haven't found a decent answer.
It's about my connectionstring in my web.config of my ASP.NET MVC application
This is my connectionstring:
<add name="DefaultConnection" connectionString="Server=tcp:****.database.windows.net,1433;Initial Catalog=***;Persist Security Info=False;User ID=****;Password=******;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" providerName="System.Data.SqlClient" />
I also have a second, which works perfectly:
<add name="treinsqlEntities" connectionString="metadata=res://*/TreinDB.csdl|res://*/TreinDB.ssdl|res://*/TreinDB.msl;provider=System.Data.SqlClient;provider connection string="data source=*****.database.windows.net,1433;initial catalog=*****;user id=*****;password=******;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
It works perfectly on localhost, but it doesn't online, (The database and site is hosted on Azure) so the pasword and username are definitly correct.
I use this connectionstring to log in/register, sign up, ...
What's the problem?
Huge thank you in advance to all you lifesavers!
Edit: This is the exception:
enter image description here
These are my firewall settings: enter image description here
That is likely because you have not opened the firewall up to all azure connections. By default there are no firewall rules added to your new databases/server in Azure. You have probably added your local client IP but not checked the box that is for all Azure connections. https://learn.microsoft.com/en-us/azure/sql-database/sql-database-firewall-configure#overview The section 'Connecting from Azure' should point you to the right setting.
Please be aware that this allows all IP's originating from Azure a connection into you DB. It does not allow access since your authentication mechanism will stop that but connections will be allowed from any subscription in Azure with this option checked.

Database connection not working in ASP MVC

I just create a new ASP MVC sample. The code was generate with scaffolding. Then I run the application and it runs smooth. But when I click "Register" link in top nav bar and tries to register it does not work.
My Connection String:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-ProductExa‌​mple-20151218101004.mdf;Initial Catalog=aspnet-ProductExample-20151218101004;Integrated Security=True" providerName="System.Data.SqlClient" />
It is saying that your connection with sql server is not established.
Please check your connection string.
Here i am showing mine. Please check it once. It may help you.
<connectionStrings>
<add name="DemoEntities" connectionString="metadata=res://*/Models.Report.DemoEntities.csdl|res://*/Models.Report.DemoEntities.ssdl|res://*/Models.Report.DemoEntities.msl;provider=System.Data.SqlClient;provider connection string="data source=192.168.1.2\SQLEXPRESS;initial catalog=DEMODB;user id=abc;password=abc;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
Check all following parameters are correct or not.
data source=192.168.1.2\SQLEXPRESS;
initial catalog=DEMODB;
user id=abc;
password=abc;
According to your sql server configuration you need to correct your connection string.
I needed to write IP\InstaceName may be in your you only need to write IP or only instace name. Please check it once.
check sql server express is install or not on your machine if not then use local sql server that is install on your machine and change connection string
data source=.;
initial catalog=DEMODB;
user id=abc;
password=123;

Proper format for SQL Server Connection String on 1and1.com

I have spent several hours trying to search this on the web in addition to calling and emailing support at 1and1.com web hosting with no success.
I have ASP.NET pages which connect to MS SQL Server database using the entity framework. On my local machine, all works fine (naturally). However, when I modify the connection string in my web.config to point to my SQL Server database on 1and1.com, I get the following error:
"Unable to load the specified metadata resource."
Here's my current connection string (as defined in my web.config file):
<add name="TimeDataLicenseEntities"
providerName="System.Data.EntityClient"
connectionString="metadata=res://*/
Model1.csdl|res://*/
Model1.ssdl|res://*/
Model1.msl;
provider=System.Data.SqlClient;
provider connection string="
data source=dbXXXX.db.1and1.com,1433;
Integrated Security=false;
initial catalog=database_name;
user id=dboXXXX;
password=valid_password;multipleactiveresultsets=True"" />
(Please note that where there are 'XXXX' the values are different in the actual config file as well as for 'database_name' and 'valid_password')
I'm using the Entity Framework in the code so I'd prefer solutions that correct the content of my web.config file.
Here is what ended up working for me:
<add name="TimeDataLicenseEntities"
providerName="System.Data.EntityClient"
connectionString="metadata=
res://<assemblyname>/Model1.csdl|
res://<assemblyname>/Model1.ssdl|
res://<assemblyname/Model1.msl;
provider=System.Data.SqlClient;
provider connection string="
data source=dbXXXX.db.1and1.com,1433;
Integrated Security=false;
initial catalog=database_name;
user id=dboXXXX;
password=valid_password;
multipleactiveresultsets=True"" />
By including the assemblyname for my code in the sections above (the brackets ('<' and '>') should not be included), I was able to finally get it to work.
Thanks all for your assistance.
Here is what actually works on 1and1 server from ASP.NET Code first design. So, simply replace your serverName, DatabaseName, UserID, and Password.
<add name="DefaultConnection"
connectionString="Data Source=dbXXX.db.1and1.com,1433;Initial Catalog=dbYYYYY;Integrated Security=False;user id=dboZZZZZ;password=YOURDBPASSWORD;MultipleActiveResultSets=True;Application Name=EntityFramework"
providerName="System.Data.SqlClient" />
Hope this can help anyone looking to use 1and1 asp.net server since their customer service is pretty useless.

ASP.NET Wepapplication with on-disk database - how?

How can I use an .mdf file (called SQL Server Database in VS2012) for Entity Framework?
I get this error message:
Invalid value for key 'attachdbfilename'.
This is my connectionstring:
<add name="DbContainer" connectionString="metadata=res://*/Database.Db.csdl|res://*/Database.Db.ssdl|res://*/Database.Db.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDb)\v11.0;initial catalog=DataContext;Integrated Security=True;AttachDBFilename=|DataDirectory|\DataContext.mdf;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />.
In Global.asax.cs, Application_Start I set the correct path for |DataDirectory| like this:
string newPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data");
AppDomain.CurrentDomain.SetData("DataDirectory", newPath);
Do any of you know to make this work?
Btw. it works when running my web application locally (i.e. debug), and does not work when publishing to my online domain.
If it works locally but not online, the problem is from data source part of your connection string. And if you want to attach your db at runtime, not by management studio, remove the initial catalig part. So change it to something like the following:
<add name="DbContainer"
connectionString="metadata=res://*/Database.Db.csdl|res://*/Database.Db.ssdl
|res://*/Database.Db.msl;provider=System.Data.SqlClient;
provider connection string="data source=RemoteServerInstance;
Integrated Security=True;AttachDBFilename=|DataDirectory|\DataContext.mdf;
MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />

SQL Express connection string hell ASP.Net

SQL Express 2005 is running locally. I have a project written by another person running on the same machine. All I want to do is connect to it, can't be that hard right?
This is the one I use in my old classic ASP code to hit another database running on the same instance:
Provider=SQLOLEDB;Data Source=MYLAPTOP\MSSMLBIZ;Persist Security Info=True;User ID=TestUser;Password=letmein;Initial Catalog=TestDB
But trying a version of that makes the .net code throw a wobbler as he's written it using SQLServer drivers so its not liking the Provider stuff.
Here is the orginal connection string from his code:
Server=(local);Initial Catalog=TheDatabase;User Id=TheUser;Password=ThePassword;
I've been to http://www.connectionstrings.com/sql-server-2005 and tried several of the options from there, these all get "SQL Server does not exist or access denied" (what a lovely mixed error message that is!):
Data Source=localhost;Integrated Security=True;Initial Catalog=TheDatabase
Data Source=localhost\SQLEXPRESS;Integrated Security=True;Initial Catalog=TheDatabase
Data Source=MyLaptop\SQLEXPRESS;Integrated Security=True;Initial Catalog=TheDatabase
Server=MyLaptop\SQLEXPRESS;Initial Catalog=TheDatabase;User Id=TheUser;Password=ThePassword;
I've created logins for MyLaptop/IUSR_MyLaptop, MyLaptop/ASPNET, MyLaptop/IWAM_MyLaptop in SQL Express and given them all read/write permissions to my DB and set their default DB to be TheDatabase.
What the heck am I doing wrong and how can I debug the problem some more?
UPDATE: Special Thanks to Chris for all his pointers, got there in the end, if you are having similar problem please read all the comments there are lots of links and tips on how to track them down.
Can you advise exactly what is in the config?
Are you using the block - in which case a valid connection string would be:
<add name="connection" providerName="System.Data.SqlClient" connectionString="Data Source=localhost\MSSMLBIZ;Initial Catalog=TheDatabase;Integrated Security=True" />
or
<add name="connection" providerName="System.Data.SqlClient" connectionString="Data Source=localhost\MSSMLBIZ;Initial Catalog=TheDatabase;Integrated Security=False;User Id=TheUser;Password=ThePassword;Application Name=AppName;" />
Or are you getting the connection string from app settings - in which case I guess your provider is set in code inside the app itself?
With that error message in your comment you should run through the items in http://blogs.msdn.com/sql_protocols/archive/2007/05/13/sql-network-interfaces-error-26-error-locating-server-instance-specified.aspx
I presume the instance is running and does allow connections over tcpip?
Shouldn't your datasource read: Data Source=localhost\sqlexpress too?
You don't mention granting rights for 'TheUser' to access the database on the server - if you're restored from another server you may had a sid mismatch.
Try running
sp_update_users_login 'report'
against the db in question.
If it returns the user account in the report try:
sp_update_users_login 'update_one', 'theuser', 'theuser'
to remap things.

Resources