strange issue in connection string from visual studio - c#

Hi I am not able to connect I get an error server was not found, the problem is my connection string in the data source property in web config.
<connectionStrings>
<add name="dbHolaStaffConnectionString" connectionString="Data Source=localhost\SQL2016;Initial Catalog=dbHolaStaff;user id=xx;password=xx;MultipleActiveResultSets=True;Application Name=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>
I have chnaged the source in many ways but cant get it work.
DESKTOP-VNAJJMF\SQL2016
.\SQL2016
localhost\SQL2016
The server name in sql management studio is: DESKTOP-VNAJJMF\SQL2016
My user id and passwords are correct, how can I fix this problem? I dont know why visual studios keeps showing that error.
I also have enabled Remote access in sql server but nothing works.

Can you try with the below one
<connectionStrings>
<add name="dbHolaStaffConnectionString" connectionString="Server=DESKTOP-VNAJJMF\SQL2016;Database=dbHolaStaff;user id=xx;password=xx;MultipleActiveResultSets=True;Trusted_Connection=True;Application Name=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>

Related

Get SQL Connection error while using Web Service with local SQL Server database

I'm setting up a web service, I wanted to use the local database so I created a local SQL Server database in this project. The web service runs just fine on localhost, but the problem when I invoke a method to Load data from the local database on this project, I'm getting an error:
System.Data.SqlClient.SqlException:
An attempt to attach an auto-named database for file C:\Program Files (x86)\IIS Express\TourTravelDB.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
TourTravelDB.mdf is my local database
I've added a connection string in my web.config but it's still not working.
Here is my connection string.
<connectionStrings>
<add name="CS"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\TourTravelDB.mdf;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
I've also tried to move my database to the IIS Express directory, it works but when run it from another computer, I have to move the database again.
Does anyone have an idea how to solve this?
This may help you..
Add "User Instance=True;" in your connection string.
<connectionStrings>
<add name="aspnet_staterKits_Test_TimeTracker"
connectionString="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|aspnetdb.mdf;"/>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer"
connectionString="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|aspnetdb.mdf;"/>
</connectionStrings>
if doesn't work then try out the below links..
forums.asp.net
codeproject.com
Already existing thread in stack overflow

EF 6 "Unable to load the specified metadata resource" -- but I'm not using edmx

Sorry if this has been asked, but I've gone through all of the other posts I can find and everyone seems to be using an EDMX, and not a "production" database.
I get the following error:
System.Data.Entity.Core.MetadataException: Unable to load the specified metadata resource
when attempting to access my application. My connection string is as follows:
<add name="FormAssemblyEntities" connectionString="metadata=res://*/Models.Entities.FormAssembly.csdl|res://*/Models.Entities.FormAssembly.ssdl|res://*/Models.Entities.FormAssembly.msl;provider=System.Data.SqlClient;provider connection string="data source=server\instance;initial catalog=dbname;user id=userid;password=password;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
This works perfectly if I am running it locally and it connects to the edmx with the following connection string, but as soon as I put it on our UAT server and point it to the database, I get that error.
<add name="FormAssemblyEntities" connectionString="Data Source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\FormAssembly.mdf;Initial Catalog=FormAssembly;Integrated Security=SSPI;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
I really have no idea where to start. The database appears up to date, the user has access, and the server has access to the SQL server.
I have also tried replacing the res://*/ with res://FormAssembly/ and res://FormAssembly.dll/, but the former results in the same error, and the latter says the dll can't be found (the DLL is in the bin directory).
Any help would be appreciated.
Thanks,
Travis
In my case, the metadata part of my connection string was malformed.
The following connection string worked in my case:
<connectionStrings>
<add name="NorthwindEntities" connectionString="metadata=res://*/Northwind.csdl|res://*/Northwind.ssdl|res://*/Northwind.msl;provider=System.Data.SqlClient;provider connection string="data source=(local);initial catalog=Northwind;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework""
providerName="System.Data.EntityClient" />
</connectionStrings>

Connecting to mdf database with Web.config ASP.NET

I tried many things and saw a lot of information on the internet. It just doesn't work and I want to know what am I doing wrong.
I created a .mdf database in my App_Data folder and trying to connect it through Web.config.
my <connectionString /> looks like this:
<add name="Datab1" connectionString="Data Source=.\SQLExpress;AttachDbFilename=|DataDirectory|Datab1.mdf;Database=Datab1; Trusted_Connection=Yes;" />
And I also tried this:
<add name="Datab1" connectionString="Data Source=.\SQLEXPRESS;
AttachDbFilename=E:\Secret\Secret\App_Data\Datab1.mdf;
Integrated Security=True;
User Instance=True"/>
The providerName="System.Data.Client" />gives me an error so I removed it.
What am I doing wrong here?
I finally fixed it by going to Server Explorer > Connect to Database > Data source to "Microsoft SQL Server Database File (SqlClient)" and Db file name browse to the .mdf file you want to use. Use Windows Authentication.
in the Web.config use this string:
<add name="Datab1" connectionString="Data Source=(localdb)\v11.0;AttachDbFileName=path\to\folder\of\database\Datab1.mdf;Integrated Security=True" providerName="System.Data.SqlClient"/>
And replace Datab1 with your own database name of course. This worked for me so this question is solved!

WPF app SQL connection string error

This question has probably been asked a thousand times but all the answers that I have seen are not relevant to my question.
I have an asp.net web site setup locally to connect to sql and I used the exact same connection strings in the WPF App.config file
<connectionStrings>
<add name="TrackingConnection" providerName="System.Data.SqlClient" connectionString="Data Source=RAIDSHIPPING\FRTOOLS; Initial Catalog=SHIPPING; User Id=sa; Password=password" />
<add name="RMAConnection" providerName="System.Data.SqlClient" connectionString="Data Source=RAIDSHIPPING\FRTOOLS; Initial Catalog=FRTOOLSRMA; User Id=sa; Password=password" />
<add name="PickListConnection" providerName="System.Data.SqlClient" connectionString="Data Source=RAIDSHIPPING\FRTOOLS; Initial Catalog=Picklist; User Id=sa; Password=password" />
<add name="ShipWorksConnection" providerName="System.Data.SqlClient" connectionString="Data Source=RAIDSHIPPING\FRTOOLS; Initial Catalog=ShipWorks; User Id=sa; Password=password" />
<add name="SupplyConnection" providerName="System.Data.SqlClient" connectionString="Data Source=RAIDSHIPPING\FRTOOLS; Initial Catalog=SupplyManager; User Id=sa; Password=password" />
</connectionStrings>
As usual this works on the local machine but on the network machine I get a "A network-related or instance-specific error occurred while establishing a connection to SQL Server." error.
Like I said this connection string is copied exactly from the asp.net web application, web.config file connection string which the network machine consumes fine. I have the App.config properties set to Copy always also the Sql server configuration is set up to enable Named Pipes and TCP/IP. Windows Firewall has port 1433 open. I thought the Copy always property being set would have solved the problem since the program wouldn't work because images were causing it to break until I set their properties to copy always. I've restarted the SQL Server and machine.

Cannot Access To ASP.NET Configuration Tool

When I want to access to ASP.NET Configuration Tool it gives me the following error message:
There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.
The following message may help in diagnosing the problem: Unable to connect to SQL Server database.
What can I do. Is there any configuration which I should set before I can access or ?
I am using ASP.Net MVC4 Project with build in connection string.
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-AccountPortal-20131128183241;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-AccountPortal-20131128183241.mdf" providerName="System.Data.SqlClient" />
you should access your connection string from web.config file before proceeding further.
web.config file :
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-AccountPortal-20131128183241;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-AccountPortal-20131128183241.mdf" providerName="System.Data.SqlClient" />
</connectionStrings>
from code : access connection string which is in web.config file
string connectionstring = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

Categories

Resources