How to set connectionString of .NET web application with database in Docker - c#

I am running Visual Studio in MAC OS. I have a web application developed in .NET. I want to attach this application with a database that I was able to configure and run using Docker in a localhost server.
If I were to work in Visual Basic (in windows) what I usually do to connect to the database is modify the "DefaultConnection" of the Web.config file:
<add name="DefaultConnection" connectionString="Data Source=mypc\SQLEXPRESS;Initial Catalog=MyDataBase;Integrated Security=True" providerName="System.Data.SqlClient" />
But in the case of MAC, as I am running the server in Docker, I don't know what should be the connection string. My question is how to find the string or what should I use as connectionString in this case where the database is in Docker.

Related

ASP.NET MVC : change connection from SQL Server 2012 to SQL Server 2014

I have an existing ASP.NET MVC project which previously was connecting to SQL Server 2012. But now I have only SQL Server 2014 installed and it can not connect.
connectionString="Data
Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspn‌​et-Vidly-20160330105‌​730.mdf;Initial
Catalog=aspnet-Vidly-20160330105730;Integrated Security=True"
My Sql Server works ok, I have version problem, the project is taken from another pc Which had installed SQL-Server 2012 , Now I am trying to run with SQL-Server 2014 installed !!!
It is trying to connect to SQL Server 2012. How can I fix this?
This question may already have an answer here: - I could not find anything helpful.
Looks like there is a problem with your connection string in the application.
This is the standard connection string to connect local DB:
<add name="ConnectionStringName"
providerName="System.Data.SqlClient"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFileName=|DataDirectory|\DatabaseFileName.mdf;InitialCatalog=DatabaseName;Integrated Security=True;MultipleActiveResultSets=True" />
An example with credentials:
<add name="ConnectionStringName"
providerName="System.Data.SqlClient"
connectionString="Data Source=ServerName;Initial Catalog=DatabaseName;Integrated Security=False;User Id=userid;Password=password;MultipleActiveResultSets=True" />
For more information visit: https://msdn.microsoft.com/en-us/library/jj653752(v=vs.110).aspx

C# How to deploy/create setup for VS application with localdb?

Im trying to deploy application application with localdb. What I currently achieved is that I created mdf file from my localdb and add it to setup project (Visual Studio Installer). I modified connection of mdf file to localdb database. What I'm worried about this solution, when I'll edit database and install updates on client PC, if the data from mdf file will be lost. Is there a better way how to deploy or is this method valid?
Problem with this method is that I cant reach my stored procedure, even server explorer shows them.
Using VS 2015, SQL Server 2016 and EF 6 in my app.
Connection string, first one was initial one, connecting right to localdb, second one is connecting to mdf file. First one si working correctly, but only on dev machine, second one is having problems.
<connectionStrings>
<add name="MSDBContext" connectionString="data source=(localdb)\MSSQLLocalDB;initial catalog=MSDatabase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
<add name="MSDBContextFile" connectionString="data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\MSDB.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>

How to add data directory in connection string to deploy application on client machine?

I created an windows form application in c# during development i used following connection string and it works fine
<connectionStrings>
<add name="myconnection" connectionString="Data Source=ABC-PC\SQLEXPRESS;Initial Catalog=mydatabase;Integrated Security=True"/>
</connectionStrings>
but now i need to deploy application on client machine and i have to add data directory option in my connection string and i did this as
<connectionStrings>
<add name="myconnection" connectionString="Data Source=.\SQLEXPRESS; Integrated Security=True; User Instance=True;AttachDbFilename=|DataDirectory|\mydatabase.mdf; Initial Catalog=mydatabase; "/>
</connectionStrings>
when i changed string then it threw and error
Unable to open the physical file "D:\Other Projects\Employee\Employee\bin\Debug\mydatabase.mdf". Operating system error 2: "2(The system cannot find the file specified.)".
Cannot attach the file 'D:\Other Projects\Employee\Employee\bin\Debug\mydatabase.mdf' as database 'mydatabase'.
and calling connection string as
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["myconnection"].ConnectionString);
I used SQL server 2008.
After a lot of research plus hit an try i found solution that connection string is correct a thing that i did is to copy database files from SQL server's folder to project folder. Now it is working fine according to my requirement.

the Error "Connection string not found in application config file" occurs EF 6.1.1, even though it is in the Web Config for the project

I have a WCF service base on the .net framework 4.5.1 that uses several DLLs built around the EntityFramework 6.1.1 , I use them in multiple web sites and web services, but it seems that suddenly all new WCF projects I create cannot find the connection strings. The error is
"No connection string named 'MemberEntities' could be found in the application config file." Connection string name 'MemberEntities' will of course vary depending on what model I am trying to access.
<connectionStrings>
<add name="CoachingEntities" connectionString="metadata=res://*/CoachingModel.csdl|res://*/CoachingModel.ssdl|res://*/CoachingModel.msl;provider=System.Data.SqlClient;provider connection string="data source=SomeServer.com;initial catalog=CoachDB;persist security info=True;user id=SomeUser;password=SomePasswd;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient"/>
<add name="MemberEntities" connectionString="metadata=res://*/MemberModel.csdl|res://*/MemberModel.ssdl|res://*/MemberModel.msl;provider=System.Data.SqlClient;provider connection string="data source=SomeServer.com;initial catalog=MembersDB;persist security info=True;user id=SomeUser;password=SomePasswd;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient"/>
<add name="QuestionnaireEntities" connectionString="metadata=res://*/QuestionnaireModel.csdl|res://*/QuestionnaireModel.ssdl|res://*/QuestionnaireModel.msl;provider=System.Data.SqlClient;provider connection string="data source=SomeServer.com;initial catalog=QuestionnaireDB;persist security info=True;user id=SomeUser;password=SomePasswd;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient"/>
</connectionStrings>
All of the connection strings have been added to the web config (as shown) for the WCF project just as I have added it to all of the Asp.Net web forms applications in the past, all of which work fine. I have created new clean solutions multiple times and they all have the same problem.
I have previously done the same with WCF web services. Is there some new requirement or something else that I could be missing? I have seen this error before but copying the connection string from the Class project’s app config to the WCF or Website’s web.config has always solved the problem until now.
Any thoughts or ideas would be greatly appreciated. I am using Visual Studio 2013 Pro on Windows 8.1

What should be the connection string for a default profile provider in windows azure?

I am using system.web.providers to implement basic authentication for my APIs in my windows azure project. This is my default connection string which am using
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-myProject.WebRole-20130117071735;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-myProject.WebRole-20130117071735.mdf;MultipleActiveResultSets=True" />
And in my AppData folder the .mdf file is being created. But when i deploy to my azure account am getting the following error.
{"Message":"An error has occurred.","ExceptionMessage":"The system cannot find the file specified","ExceptionType":"System.ComponentModel.Win32Exception","StackTrace":null}
I know the error doesnt give any information, but this is happening only for the APIs i have put the basic authentication so i guess the problem is that .mdf file isnt being created on cloud.
Any idea what the connection string should be when I deploy to cloud?

Categories