Entity framework with db mode cannot connect to server - entity-framework

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"

Related

SQL Server 2016 Express and LocalDb connection issues

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?

Create db2 dataSource in WAS liberty profile

I am developing for Websphere 8.5 (for z/OS), but i would like to use Liberty for local development on my Windows machine. I can't get the data source to work.
I created the following entry in the Server.xml to define the data source.
<library id="DB2JCC2Lib">
<fileset dir="C:\Program Files\IBM\SQLLIB\java"/><!--includes="db2jcc.jar db2jcc_license_cu.jar db2jcc_license_cisuz.jar"-->
</library>
<dataSource id="xxdb" jndiName="jdbc/xxxx" type="javax.sql.ConnectionPoolDataSource">
<jdbcDriver libraryRef="DB2JCC2Lib" id="db2-driver" javax.sql.ConnectionPoolDataSource="com.ibm.db2.jcc.DB2ConnectionPoolDataSource"/>
<properties.db2.jcc driverType="2" databaseName="xxxx" portNumber="50000" user="xxxx" password="{aes}xxxx"/>
</dataSource>
When my application initializes i get the following error message:
[jcc][4038][12241][3.61.65] T2LUW exception: SQL30081N Kommunikationsfehler. Verwendetes Kommunikationsprotokoll: "TCP/IP". Verwendete Kommunikations-API: "SOCKETS". Position, an der der Fehler erkannt wurde: "127.0.0.1". Übertragungsfunktion, die den Fehler festgestellt hat: "connect". Protokollspezifische(r) Fehlercode(s): "10061", "", "". SQLSTATE=08001
I think this message comes from the db2 Driver, unfortunately i didn't find a way yet to change it to english; but i think it's understandable for english speakers.
I have an ODBC System datasource that connects to DB2 v10 maintenance level 015 for z/OS. My local DB2 Connect Installation is v9.7.300.3885.
In my regular Websphere my working datasource has driver type 2, database Name set to the odbc-name and port number 50000. Server name is not set (empty). Classpath and implementation class is the same that i provided in the server.xml
I have tried everything i could find, any ideas?
Note: I can't make changes on the db2 server and there is no issue connecting to the database with other tools and the regular WebSphere.
Also the server name in the websphere configuration is empty, only database name is set. When i tried to set the servername in the server.xml to localhost or the db2 server i got the same result.
Any help is appreciated!
Edit: updated with correct Version Information
Edit 2: As long as it works i dont care what type (2 or 4) of the jdbc driver is used. I just want to point out again that type 2 is currently working on my machine. I tried it with type 4 and got the following message:
[jcc][t4][2043][11550][3.61.65] Exception java.net.ConnectException: Error opening socket to server xxx/xxx.30.3.34 on port 50,000 with message: Connection refused: connect. ERRORCODE=-4499, SQLSTATE=08001 DSRA0010E: SQL State = 08001, Error Code = -4,499
Sorry, previous post ate my xml. Trying again:
You will need a type 4 datasource to connect to a remote database server, i.e.,
<dataSource id="xxdb" jndiName="jdbc/xxxx" type="javax.sql.XADataSource">
<properties.db2.jcc driverType="4" serverName="the.db2.host.com" portNumber="50000" user="xxxx" password="xxxx" databaseName="LOC1" currentSQLID="SYSA"/>
<jdbcDriver libraryRef="DB2JCC2Lib">
</dataSource>
Type 2 is only for a local z/OS connection to a database resource. Your Windows, being remote from z/OS, requires you to use a type 4 connection. Type 4 requires both the serverName and portNumber to be specified. These are not applicable on a type 2 connection.

SQL Server 2008 R2 - Unable to rebuild master database, Cannot shutdown service

Yesterday I noticed I could not execute any query within the master database. I tried a DBCC CHECKDB but this just hung (let it run for 24 hours). I was unable to stop the SQL Server service: "The service cannot accept control messages at this time"
I decided to try to rebuild the master database: setup /ACTION=REBUILDDATABASE /QUIET /INSTANCENAME=MYINSTANCE /SQLSYSADMINACCOUNTS=MYACCOUNT /SAPWD=MYPASSWORD
Summary.txt seems to indicate the same problem:
Detailed results:
Feature: Database Engine Services
Status: Failed: see logs for details
MSI status: Passed
Configuration status: Failed: see details below
Configuration error code: 0x0A2FBD17#1211#1
Configuration error description: The service cannot accept control messages at this time.
Configuration log: C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\20140517_091501\Detail.txt
It looks like the SQL Server cannot be shutdown. What can I do about this?
"SHUTDOWN WITH NOWAIT" looks to have fixed the problem.

Entity framework - The provider did not return a ProviderManifestToken string error

I am using SQL Server 2005 Express with SQL Servre authentication and remote connections enabled although I am working locally.
My web.config connection string part:
<add name="HelpDesk2connect" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string='Data Source=SATURN;Initial Catalog=HelpDesk2;Integrated Security=False;user id=sa;password=*******;multipleactiveresultsets=true'" providerName="System.Data.EntityClient" />
I am logging in as sa
In the controller I get these errors (in this statement: `return View(db.Tickets.ToList());)
An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct.
The provider did not return a ProviderManifestToken string.
In the page I get this error:
[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: 52 - Unable to locate a LocalDB installation. Verify that SQL Server Express is properly installed and that the LocalDB feature is enabled.)]
Can you help me spot what am I doing wrong?
Thanx in advance

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.