SQL Server 2016 Express and LocalDb connection issues - localdb

I'm having a difficult time getting localdb running under IIS in the connection strings. I am running:
Windows 10
SQL Server 2016 Express and LocalDb installed
I added the following to my applicationHost.config, which I would not like to do if possible, but it changed the original error I was getting about not connecting:
<applicationPools>
<add name="myappPool"
autoStart="true" managedRuntimeVersion="v4.0">
// Added this <processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />**
</add>
<applicationPoolDefaults managedRuntimeVersion="v4.0">
<processModel identityType="ApplicationPoolIdentity"
loadUserProfile="true" setProfileEnvironment="false" />
</applicationPoolDefaults>
</applicationPools>
The myAppPool is running under ApplicationPoolIdentity but changing this to another level of like LocalService doesn't help.
I am now getting this error:
An attempt to attach an auto-named database for file
C:\_sites\mySite\Databases\MyDb.ldf failed. A
database with the same name exists, or specified file cannot be
opened, or it is located on UNC share.
Here is my connection string:
<add name="core"
connectionString="Server=(localdb)\mssqllocaldb;Integrated Security=true; AttachDbFileName=C:\\_sites\mySite\Databases\MyDb.ldf;" />
I can verify that I can connect to (localdb)\mssqllocaldb if Management Studio. I was assuming that localdb meant I did not have to attach the db like I regularly do with sql if using the connection string above. I even added anonymous logon to the file security of the files just to see what would happen.
Any ideas?

Related

Entity framework with db mode cannot connect to server

I am trying to connect to by db instance using db first, I created a connection
<add name="Entities"
connectionString="metadata=res://*/Models.ModelCmarket.csdl|res://*/Models.ModelCmarket.ssdl|res://*/Models.ModelCmarket.msl;provider=System.Data.SqlClient;provider connection string="data source=(localdb)\v12.0;initial catalog=Cevaheer;integrated security=True;trustservercertificate=False;multisubnetfailover=True;MultipleActiveResultSets=True;multipleactiveresultsets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
And I always get an 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: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist.)
But if i try
<add name="CevhermarketEntities"
connectionString="Data source=(localdb)\v12.0;initial catalog=Cevaheer;integrated security=True;trustservercertificate=False;multisubnetfailover=True;MultipleActiveResultSets=True;user id=dbuser;password=flexsin#123!;multipleactiveresultsets=True;"
providerName="System.Data.SqlClient" />
I can connect, and also can connect from VS sql server explorer and SSMS.
To begin - there are 4 issues that could be causing the common LocalDb SqlExpress Sql Server connectivity errors SQL Network Interfaces, error: 50 - Local Database Runtime error occurred, before you begin you need to rename the v11 or v12 to (localdb)\mssqllocaldb
You dont have the services running
You don't have the firelwall ports here
configured
Your install has and issue/corrupt (the steps below help give you a nice clean start)
You did not rename the V11 or 12 to mssqllocaldb
I found that the simplest is to do the below - I have attached the pics and steps for help.
First verify which instance you have installed, you can do this by checking the registry and by running cmd
cmd> Sqllocaldb.exe i
cmd> Sqllocaldb.exe s "whicheverVersionYouWantFromListBefore"
if this step fails, you can delete with option d cmd> Sqllocaldb.exe d "someDb"
cmd> Sqllocaldb.exe c "createSomeNewDbIfyouWantDb" create - the pic is error
cmd> Sqllocaldb.exe start "createSomeNewDbIfyouWantDb"

Why won't my connection string work?

Could someone tell me why my connection string isn't working.. i'm currently using database first, but don't know why it wont connect. Whenever i try i get the error
'The network path was not found'
connection string is:
<add name="FactsAndFiguresEntities1" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string='data source=SERVERNAME User Id=****; Password = **** catalog=FactsAndFigures;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework'" providerName="System.Data.EntityClient" />
The error network path not found, could refer to how you are referencing the metadata files. When you use "res://" EF tries to load the metadata from assemblies in the bin catalogue of the application. Do you have a bin catalogue?
Also I notice that you use both Integrated Security=True and Username/password. The system will use one or the other not both.
For details on EF connection strings see: https://msdn.microsoft.com/en-us/library/vstudio/cc716756(v=vs.100).aspx

can't change connection string (ODP, Oracle, Linq to Entities)

I have a App.config connection string that connects me to my database just fine:
<add name="SFEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=Oracle.DataAccess.Client;provider connection string="DATA SOURCE=micahs_poc_dev_server.kci;PASSWORD=kierkegaard;PERSIST SECURITY INFO=True;USER ID=KIERKEGAARD"" providerName="System.Data.EntityClient" />
I am using an ODP reference in conjunction with an ADO.NET / Linq to Entities approach.
The trouble comes when I want to connect to a different database (with the same schema) on our network.
<add name="SFEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=Oracle.DataAccess.Client;provider connection string="DATA SOURCE=QA_ETL_TEST_SERVER.COM;PASSWORD=bigshotpassword;PERSIST SECURITY INFO=True;USER ID=CoolidgeCalvin"" providerName="System.Data.EntityClient" />
When I just change the name of the server I get this error:
ORA-00942: table or view does not exist
I can actually run several lines of code before it throws an exception:
using (SFEntities ctx1 = new SFEntities())
{
var ds = ctx1.Connection.DataSource; // debugger: QA_ETL_TEST_SERVER.COM
var db = ctx1.Connection.Database;
var dstate = ctx1.Connection.State;
var dsite = ctx1.Connection.Site;
ctx1.Connection.Open();
SF_CHANGE_ORDER cotest = new SF_CHANGE_ORDER();
cotest.DELETE_FLAG = "D";
var result = (from cp in ctx1.SF_CLIENT_PROJECT
select cp).ToList(); // <--- error here!
I also tried changing the format to this:
<add name="SFEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=Oracle.DataAccess.Client;provider connection string="DATA SOURCE=(DESCRIPTION =(ADDRESS=(PROTOCOL=TCP)(HOST=155.32.75.11)(PORT=65550))(ADDRESS=(PROTOCOL=TCP)(HOST=155.32.75.11)(PORT=65550))(CONNECT_DATA=(SERVICE_NAME=QA_ETL_TEST_SERVER.COM)(FAILOVER_MODE=(TYPE=SELECT)(METHOD=BASIC)(RETRIES=180)(DELAY=5))));PASSWORD=bigshotpassword;PERSIST SECURITY INFO=True;USER ID=CoolidgeCalvin"" providerName="System.Data.EntityClient" />
Which basically mirrors the TNS entry I have for this server. I still get the 'does not exist' error.
If I make the server name something goofy I get a TNS error saying that server isn't recognized. So I am pretty sure it is picking up the server name I want and checking to see it is there.
I don't think it is a table permissions/creation issue because I can query them just fine on both databases from the same machine with the same credentials (and same TNS file).
[note: I changed the server/user/pw in the strings]
[edit: tried bringing up fiddler, but I didn't see any messages pass through]
Ah ... VisualStudio tucks away the schema name in the Model .edmx file. To make it work you have to somehow open the model file (use notepad or search all documents in the project) and manually change the schema name. Boo!

Entity Framework database not working (Code First, Web Deploy)

I'm using Asp.Net MVC4 with Entity Framework Code First.
Everything works locally, but when I publish, pages without database access work (on the internet), and any page with it, loads for an age, then gives me a server error.
I have enabled migrations, I have made an InitialCreate migration that is using the current model. I have ran the "Update-Database" command without error.
Any ideas ?
EDIT, thanks to the comment below, here is some detailed information on the 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Error in stack trace...
[SqlException (0x80131904): 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)]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5064458
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo,
SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout,
Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean
integratedSecurity) +341
Also I'm using .sdf database's. Connection strings here...
<add name="DefaultConnection" connectionString="Data Source=|DataDirectory|Data.sdf" providerName="System.Data.SqlServerCe.4.0" />
<add name="ZDataContext" connectionString="Data Source=|DataDirectory|ZData.sdf" providerName="System.Data.SqlServerCe.4.0" />
I repeat, it all works locally.
Just uploaded all files manually, got this error...
Access to the database file is not allowed. [ 1884,File name = d:\virtualservers[username]\website.co.uk\wwwroot\App_Data\ZData.sdf,SeCreateFile ]
Again that works locally, and also works on none database pages, but databases pages give me the above error.

SQL Server CE: the file resolves to a path that is too long.

I'm trying to track down a SQL Server CE issue that means I cannot use SQL Server CE on a local hard drive of my computer. Clearly the error message is a bogus one as the filename is nowhere near 260 chars
The file resolves to a path that is too long.
The maximum length is 260 characters. [ File name = D:\db.sdf ]
Specifically the D: drive. I have a very simple EF code first app that I want to unit test using SQL Server Compact Edition. When I run the app the first time I try to access the database I get the error above. Originally I tried using a simple filename as the Data Source in the connection string:
<add name="MyContext"
connectionString="Data Source=db.sdf"
providerName="System.Data.SqlServerCe.4.0" />
but got the error.
Then I tried specifying the root drive:
<add name="MyContext"
connectionString="Data Source=D:\db.sdf"
providerName="System.Data.SqlServerCe.4.0" />
and got the same error
If I tried using either a network drive or the c drive:
<add name="MyContext"
connectionString="Data Source=C:\db.sdf"
providerName="System.Data.SqlServerCe.4.0" />
or
<add name="MyContext"
connectionString="Data Source=\\Server\path\db.sdf"
providerName="System.Data.SqlServerCe.4.0" />
The it worked fine and the db was created and the operations performed.
I tried digging around in procmon and all I could find was an Explorer.exe process reporting invalid device for the d: drive.
Any help greatly appreciated
Cheers
Dave
Sounds a bit similar to my problem
I'm using MS Sql Server Management Studio Express R2 SP1...
When I try to create a CE/sdf database on the D:drive it just blinks at me, and asks me for the db path again
I managed to create a CE db on D: via Visual Studio (the inline server manager), but SSMSE still can't access it
If I do it on the C: it works fine.
Bizarre, but I think Sql CE just hates none C drives?