How to add password connection string - connection-string

How to add password in below mentioned connection string
<connectionStrings>
<add name="Gate_App.My.MySettings.GateDbConnectionString1" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\GateDb.accdb;Persist Security Info=True "
providerName="System.Data.OleDb" />
</connectionStrings>

Use this
<connectionStrings>
<add name="Gate_App.My.MySettings.GateDbConnectionString1" connectionString=" Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\GateDb.accdb; User ID=*******; Password='*******';Persist Security Info=True "
providerName="System.Data.OleDb" />
</connectionStrings>

<connectionStrings>
<add name="Gate_App.My.MySettings.GateDbConnectionString1" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=|DataDirectory|\GateDb.accdb;Persist Security Info=True;User ID=myUsername;Password=myPassword;"
providerName="System.Data.OleDb" />
</connectionStrings>
Access connection strings

Try this,
<add name="Gate_App.My.MySettings.GateDbConnectionString1" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\GateDb.accdb;User Id=id;Password=pass;" providerName="System.Data.OleDb" /

Related

Web.Config SQL Connection

My Web.Debug.Config code:
<connectionStrings>
<add name="NextLevel"
providerName="System.Data.SqlClient"
connectionString="Data Source=DESKTOP-RTOUFCH\\SQLEXPRESS;Database=NextLevel;Integrated Security=True;" />
</connectionStrings>
My CSharp code:
using System.Configuration;
using System.Web.Configuration;
using System.Data.SqlClient;
string constr = System.Configuration.ConfigurationManager.ConnectionStrings["NextLevel"].ConnectionString;
I keep getting a null reference error.
When I attempt to iterate through the connection strings, it finds one named "LocalSQLServer" which is not even in my web.Debug.config file.
What am I doing wrong?
That last comment by ThomasArdal:
I would also suggest you to publish web.config, web.debug.config, and web.release.config. If you have those files.
allowed me to figure out my problem.
I was updating web.debug.config when I should have been updating web.config.
<connectionStrings>
<add name="NextLevel"
providerName="System.Data.SqlClient"
connectionString="Data Source=.;Initial Catalog=NextLevel;Integrated Security=True;" />
</connectionStrings>
Check with this instead!

Asp.Net Identity - A network-related or instance-specific error occurred while establishing a connection to SQL Server

I have a code first EF application. The database has been created. Now I am trying to implement Login/Registration module using the Asp.Net Identity. I click the Register link but it gives me the above error.
Web.config:
...
<connectionStrings>
<add name="ConnStr_Dev"
connectionString="Data Source = DELL-MyName; Initial Catalog = MyDB_Dev; user id = sa; password=myPassword;"
providerName="System.Data.SqlClient" />
<!--<add name="DefaultConnection"
connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-MyApp-20170328111628.mdf;Initial Catalog=aspnet-MyApp-20170328111628;Integrated Security=True"
providerName="System.Data.SqlClient" />-->
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
...
<entityFramework>
<defaultConnectionFactory
type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source = DELL-MyName; Initial Catalog = MyDB_Dev; user id = sa; password=myPassword;" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
Is there something that needs to be set separately?
1- Use below connection string. I am using here SQL express instance. Replace it with the name you use to connect through sql management studio.
<connectionStrings>
<add name="ConnStr_Dev" connectionString="Server=.\SQLEXPRESS;Database=MyDB_Dev;User ID=sa;Password=myPassword;Trusted_Connection=False;Persist Security Info=False;Pooling=True;Min Pool Size=20;Max Pool Size=100;Connection Timeout=300;multipleactiveresultsets=True;App=EntityFramework" providerName="System.Data.SqlClient"/>
</connectionStrings>
2- Remove <entityFramework> tag from config file. You dont need it.
3- Make sure you are passing 'ConnStr_Dev' as string to DbContext constructor.
Locate the file IdentityModel.cs in the Models folder. In the ApplicationDbContext constructor the name of the connection string is passed in to the base class constructor - this needs to match the name of the your connection string in your web.config
So in your case
<connectionStrings>
<add name="ConnStr_Dev"
connectionString="Data Source = DELL-MyName; Initial Catalog = MyDB_Dev; user id = sa; password=myPassword;"
providerName="System.Data.SqlClient" />
</connectionStrings>
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("ConnStr_Dev", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}

Change the connection strings in MVC3 to publish in IIS

I need to change the connection strings in my mvc proyect because is local and now I need publish in a server but I dont have idea how write the connection strings and they are the next
<add name="cnn" connectionString="Data Source=SISTEMAS-PC\SQLEXPRESS;Initial Catalog=FoodGroups;User ID=FoodGroup; Password=Food" providerName="System.Data.SqlClient" />
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(SISTEMAS-PC\SQLEXPRES)\v11.0;Initial Catalog=aspnet-MvcApplication1-20130730182253;Integrated Security=SSPI;AttachDBFilename=C:\Users\Sistemas\Desktop\proyectos TI\foodGroup2\foodGroup\App_Data" />
<add name="FoodGroupsEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=SISTEMAS-PC\SQLEXPRESS;initial catalog=FoodGroups;user id=FoodGroup;password=Food;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
You have a web.config which should have a section for all your connection string.
What you need to do, is to have a web.release.config that will change the connection string when you build in release mode.
For example, web.config when you are debugging in your dev environment:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
<connectionStrings>
<add name="YourConnectionString"
connectionString="Data Source=YourServer; initial catalog=YourDatabase; Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
</configSections>
And inside the web.release.config
<?xml version="1.0"?>
<connectionStrings>
<add name="YourConnectionString"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
</configuration>
When you are building, you will see that the string "YourConnectionString" will be replaced. This way, you can deploy/publish your application depending of the build mode (debug or release) without having to modify your code and just relying on web.config.

how to change connection string entity framework in runtime

how to change connection string entity framework in runtime
code in my appconfig file :
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="RelationAtOfficeEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.;Initial Catalog=RelationAtOffice;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient"/>
</connectionStrings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
I want to change the following code :
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="RelationAtOfficeEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=127.10.10.23,1356;Initial Catalog=RelationAtOffice;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient"/>
</connectionStrings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
just data source changed.
How is it done?
When you instantiates your context it has parameter connectionString. You can change it there.

How to connect to DB on SERVER for Asp.Net membership?

I've just upload my ASPNETDB.mdf using "Generate Scripts" into server.
The problem is, I don't know how can I connect to it for my Membership.(e.g LogIn Controls)
where is the ConnectionString?
update the Data Source tag in web config
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=<<PATH Goes Here>>;Persist Security Info=False;
The connectionstring is in the web.config file.
Modify the web.config file for your application to redefine the LocalSqlServer connection string to point to the database.
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer"
connectionString="server=.;database=aspnetdb;
integrated security=sspi;"/>
</connectionStrings>
If your Membership provider is not pointing to "LocalSqlServer", then you can modify that in the web.config as well.
<membership>
<providers>
<remove name="AspNetSqlMembershipProvider"/>
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider, ..."
connectionStringName="LocalSqlServer"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
applicationName="/"
requiresUniqueEmail="false"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="7"
minRequiredNonalphanumericCharacters="1"
passwordAttemptWindow="10"
passwordStrengthRegularExpression=""
/>
</providers>
</membership>

Resources