Cannot create a local sql server 2012 - sql-server

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

Related

Can't connect SQL Server 2016 Developer via connection string generated by .edmx file

I'm working on a project using SQL Server 2008 Express. I had an instance called SQLEXPRESS and I used to connect to the DB via this connexion string :
<add name="MyConn" connectionString="metadata=res://*/MyDataModel.csdl|res://*/MyDataModel.ssdl|res://*/MyDataModel.msl;provider=System.Data.SqlClient;
provider connection string="data source=PCNAME\SQLEXPRESS;initial catalog=DbName;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
This connection string was generated by .edmx file (I'm working on an ASP.NET MVC project, database first, and Entity Framework) and it worked fine.
I recently installed SQL Server 2016 with a Developer Licence. During the install process, I used the default instance, which is MSSQLSERVER. For information, the generated InstanceID is MSSQL13.MSSQLSERVER.
I have a SQL project in my solution to regenerate my tables on my new SQL Server; I could connect easily to the server via the wizard.
I also used SQL Server Management Studio to verify everything was fine on the server, and it works perfectly (tables are generated, connection was OK).
However, my code is unable to connect to the server and systematically failed to the first call with error 26 - can't locate server instance
Here is what I've tried so far:
Change the data source parameter of the connexion string to localhost , ., .\MSSQLSERVER, .\PCNAME, PCNAME.MSSQLSERVER, PCNAME.MSSQL13.MSSQLSERVER, DOMAIN.MSSQLSERVER, DOMAIN\PCNAME => Doesn't work
Verify SQL Service are running => They are
Create an .udp file, connect to my server, and copy/paste the generated connection string : Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MyDB;Data Source=PCNAME => Doesn't work
Regenerate my .edmx file (and the connection stirng) => Doesn't work
Verify this suggestion => It was already correct
Why does all the connection wizards seems to work (SSMS,
.udl file, .edmx generator, my DB project), whereas my code is unable to reach the server? I didn't change any line of code.
EDIT : The crazy thing is I have a log database on the same server, the connexion string is
<add name="NLogConn" connectionString="Data Source=localhost;initial catalog=DBLOG;integrated security=True" providerName="System.Data.SqlClient" />
And it is actually logging the network error !! So is it really a connection string error or an EF error ? I'm using the latest EF version, 6.1.3 on each project referencing EF (The main and the DAL layers)
Before going off the deep end on what it could be let's start with a working connection string I just tested on my local machine on Visual Studio 2017 Enterprise with Entity Framework 6.1.3.
<connectionStrings>
<add name="TesterEntities" connectionString="metadata=res://*/Tester.csdl|res://*/Tester.ssdl|res://*/Tester.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=Tester;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
The marked up connection string is:
="data source=.;initial catalog=Tester;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"
For my test connection I am using my local server for a default instance also of 2016 developer edition(. is abbreviation for this). I am using integrated security and my database name(initial catalog) I am targeting is Tester.
There are a few things to consider if Entity Framework(EF) is not properly hitting a target.
What version of EF are you using? Before MS moved to Core, I believe the last .NET full edition of EF was 6.1.3. Ensure you are on the most current version on Nuget download.
If you go from Express to a full fledged SQL the connection string's 'provider' often will not be the same I believe. Or it could be the local default instance before sql is installed is different. Ensure you don't overwrite an existing connection string with this. The provider should be: 'provider=System.Data.SqlClient'
You are referencing a project of EF in ANOTHER project. Each project that references EF should be having the NuGet package for EF as well as a config file with the connection string. EG: I have a console project for testing things I write and reference another project called 'EF Testing' and I don't have an app config with a connection string. It won't work.

DNN 7 installation

I'm trying to configure a DotNetNuke 7 (DNN 7) but the following error occur
ERROR:Index #: 0
Source: .Net SqlClient Data Provider
Class: 20
Number: 2
Message:
the database is SQL server 2008 R2, both database and web server on localhost. I checked the username and all instruction in the following like carefully but nothing changed
the installation guide link
http://www.dnnsoftware.com/community/learn/video-library/view-video/video/515/view/details/dnn-7-0-installation-part-1-file-system-configuration
Check to verify that you SQL Server instance name is the Default instance, if it isn't, you'll need to change the name when connecting to it.
Something like "localhost" would work for the default instance, but if you named it something else, you would use "localhost/somethingelse"
You also should attempt to connect to your DB server using SQL Server Management Studio, with the exact same information you are trying to use in DNN.
This is an elder question, but hopefully somebody benefits from this answer.
My connection string in DNN's web.config looks like this:
<add name="SiteSqlServer" connectionString="Data Source=.\SQLExpress;AttachDbFilename=|DataDirectory|Database.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
This is an SQL Server 2016 Express instance. The MDF file will be in the App_Data folder of the DNN installation.

DNN5 Shows Under Construction

I recently upgraded my PC from Windows 7 to Windows 8.1 and am now having problems resetting up my local DNN5 environment.
I pulled my DNN5 instance down from a remote git repo, and just finished importing all of the tables/data/stored procedures from the production DB to a local instance.
I have updated the connection strings in the web.config to reflect my new database, but still, no matter what I do, I am getting redirected to http://localhost/DNN5/Install/UnderConstruction.htm.
What am I missing?
for completeness, here are my connection strings and a screencap of my db:
<connectionStrings>
<add name="SiteSqlServer" connectionString="Data Source=KMCNUTT-7\DWYATTMSSQL;Initial Catalog=DNN5;User ID=sa;Password=******"
providerName="System.Data.SqlClient" />
<add name="DNN5ConnectionString" connectionString="Data Source=KMCNUTT-7\DWYATTMSSQL;Initial Catalog=DNN5;User ID=sa;Password=******"
providerName="System.Data.SqlClient" />
</connectionStrings>
This almost always happens when you are unable to connect to the database from DNN.
Navigate to
http://localhost/DNN5/Install/install.aspx
and see if it throws a connection error just to be sure.
Is this a local database? If so try using (local)\InstanceName (I assume your instance name is DWYATTMSSQL) so (local)\DWYATTMSSQL
Also make sure that you have SQL authentication enabled in SQL server, instead of Windows Authentication only, which is the default for SQL installations.

Cannot connect to Database with Entity Framework

Every time I have a fresh install of Windows, Visual Studio and Sql Server I always have problems getting an application to connect to the local instance of Sql Server.
I am trying to start an application using Entity Framework code first. Here is my connection string.
<add name="KCSoccerDataContext"
connectionString="Data Source=.\MSSQLSERVER;Initial Catalog=KCSoccer;Integrated Security=SSPI"
providerName="System.Data.SqlClient" />
I am able to connect to the database instance using Sql Server Management Studio, but can't seem to connect using this connection string. I am assuming the problem has to do with how the database instance is configured.
The error I'm getting is
{"The provider did not return a ProviderManifestToken string."}
I'm not exactly sure what this means or where to go from here.
Any help anyone could give on this would be awesome.
Thanks
Use just this connection string:
<add name="KCSoccerDataContext"
connectionString="Data Source=.;Initial Catalog=KCSoccer;Integrated Security=SSPI"
providerName="System.Data.SqlClient" />
MSSQLSERVER is name of default instance. It is not used in connection strings. It even doesn't work from Management studio if you try using it. Only names of custom instances must by used.
You probably didn't enable remote connections for SQL Server since it's a fresh installation. Follow first solution here or here.

How can I view the data in an SQLEXPRESS DB which is connected in Web.config?

I'm running Visual Web Developer 2010 Express. I have added an additional SQLExpress DB to the standard ASPNETDB.mdf. Both are connected through the web.config. Everything runs fine. The connection strings are as follows:
<add name="TrempimModel"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|TrempimModel.mdf;
database=TrempimModel;User Instance=true"
providerName="System.Data.SqlClient" />
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;
User Instance=true"
providerName="System.Data.SqlClient" />
But how do I view the data in both DB files? To my surprise, although the files are refferenced in web.config, the DB Explorer in the IDE does not show them. If I go and add either or both in the DB explorer, strange stuff starts happening - mainly the application is not able to connect to my added DB at application launch.
So what is the best way to view SQL Express table data? Is it through the IDE, or a seperate application? And why isn't the DB explorer showing a connection established in web.config?
Thanks,
Gil
Problem Solved - surprisingly enough, by eliminating the connection sting altogether. That way, the database is created by the DB engine and attached automatically by Management Studio, so the data can be viewed over there, while debugging.
I wander why all the walk-through descriptions eliminate this option which is as hassle free as they come... One point to remember is that you need to exit the Management Studio before running the application with data model changes that will cause the DB to be re-created.

Resources