How to change database that web configuration is created?
When I use Asp.net Configuration, visual studio create a default data base (ASPNETDB.MDF),
I want use my database for my web site .
How to do this?
Just add this tab in <connectionStrings> of your Web.Config
<connectionStrings>
<add name="YourConnectionStringName"
connectionString="DataSource=yourDataSource;Initial Catalog=YourDataBaseName;User ID=YourID;Password=YourPassword"
providerName="System.Data.SqlClient" />
</connectionStrings>
You should a add database using this line in web.config
replace with aspnetdb connection string
<connectionStrings>
<add name="LoanCalculatorConnectionString" connectionString="Data Source=servername;Initial Catalog=dbname;Persist Security Info=True;User ID=888;Password=8888"
providerName="System.Data.SqlClient" />
</connectionStrings>
To this porpus use this way:
C://windows/Microsoft.net/Framework/v2.0.50727/aspnet_regsql.exe
. is run
Next--> Configuration SQL server for application service --> select server and database --> Next --> Finish
Related
I have ASP.NET MVC project.
In WebConfig file I have a connection to local db.
Here is code:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=DESKTOP-SV2O11U;Initial Catalog=RIS_Main;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="RIS_MainEntities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=DESKTOP-SV2O11U;initial catalog=RIS_Main;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
But the problem in that I working on two pcs, work and home.
So it has a different name.And I need to change DataSource in DefaultConnection
Is there any variant to keep 2 pcs name in connectionStrings?
There are two ways to solve it:
If your database server is on the same host as your application server, you can access the database via localhost host.
<add name="DefaultConnection" connectionString="Data Source=localhost;Initial Catalog=RIS_Main;Integrated Security=True" providerName="System.Data.SqlClient" />
The other way is to have multiple transformations of the same config file (like you already have with Debug and Release).
Using this way, depending on your build configuration you can have multiple completely different connection strings. Visual Studio will decide during build which one to acutually use.
Image Source
I've created a .net service that work with a database declared in web.config file. Now the project evolved and i need to query more than 1 database, how can i do this in web.config and then specify the database i want to query in the c# files?.
Here's how the current database is specified:
<connectionStrings>
<add name="stringName" connectionString="Data Source=XXXXXXXXX;Initial Catalog=DBName;Persist Security Info=True;User ID=UsrID;Password=bazinga;Application Name=AppName;Connect Timeout=20" providerName="System.Data.SqlClient"/>
</connectionStrings>
Thanks!
You just add another item to the connectionStrings section with a different name specification.
How your program calls the database is another story and I do not have the section of code which is defining the existing one. You would just need to find that and use the same method, just adding another variable to identify it.
<connectionStrings>
<add name="stringName" connectionString="Data Source=XXXXXXXXX;Initial Catalog=DBName;Persist Security Info=True;User ID=UsrID;Password=bazinga;Application Name=AppName;Connect Timeout=20" providerName="System.Data.SqlClient"/>
<add name="stringName2" connectionString="Data Source=XXXXXXXXX;Initial Catalog=DBName;Persist Security Info=True;User ID=UsrID;Password=bazinga;Application Name=AppName;Connect Timeout=20" providerName="System.Data.SqlClient"/>
</connectionStrings>
I recently built an application using visual studio express. This application was built using a local DB provided by VS express. I now have a subscription (free trial) to Microsoft Azure. What changes do I need to make to my project in order to point my project to the newly created Azure DB?
I also noticed I have 2 web.config files. one in the root directory and one in the views folder.
I believe I have to make an update to my connection string, but in a specific config file or both?
Here is my root directory web.config connection string:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source= LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-MvcMovie-20160922101748.mdf;Initial Catalog=aspnet-MvcMovie-20160922101748;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="MovieDBContext" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated Security=True" providerName="System.Data.SqlClient"/>
and my (views) web.config connection string:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-MvcMovie-20130603030321.mdf;Initial Catalog=aspnet-MvcMovie-20130603030321;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="MovieDBContext" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated Security=True"
providerName="System.Data.SqlClient"/>
Any help would be highly appreciated.
I believe only one web.config with connection strings should be enough. Keep the one in the root.
Download Azure DB connection strings from the Azure portal and replace connectionString values in the web.config file with the Azure DB connection string(s).
You might also need to whitelist your machine's IP address in the Azure Portal to allow connections to Azure DB.
You only need to change the web.config on the root folder as thats the one used by the application.
And you are right, you need to point the connection string to your Azure database.
You definitely only need to update the one web.config in the root of the application with the connection string. The other web.config in the views folder is needed for your views to use html helpers and to make routing work as you expect in an mvc application so do not remove it.
I have an ASP.net web application hosted in IIS. This application use SQL Server.
I removed connection string in web.config. But when I start the application, it is still connected to it.
The connection string was nowhere explicitly stated.
how does it work?
By default the machine.config located in C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config have the following connection string configured.
<connectionStrings>
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
By leaving the <connectionStrings> section of your web.config empty you are not removing the default connectionstring. To ensure that you have no configured connection string you should use a <clear /> element in your web.config file.
<connectionStrings>
<clear />
</connectionStrings>
I tried to use integrated security SSIP but it takes anonymous user so any developer can access the database. So anybody have any solution for this problem?
<connectionStrings>
<add name="Local2" connectionString="Data Source=ADMIN-PC\SQLEXPRESS;Initial Catalog=NEOPLAST_LIVE;username="abc" password="****" providerName="System.Data.SqlClient" />
</connectionStrings>