SQL Connection Strings when deploying to a hosting service - asp.net

I have the following connection strings in development using visual studio web developer 2010 express:
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
<add name="DatabaseConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\BegASPNET\Cheeztest\App_Data\Database.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" providerName="System.Data.SqlClient" />
<add name="DatabaseEntities" connectionString="metadata=res://*/App_Code.CheeztestModel.csdl|res://*/App_Code.CheeztestModel.ssdl|res://*/App_Code.CheeztestModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
What do I need to change/delete/keep in order to connect to a GoDaddy account with the following parameters:
Host Name: someresource.com
Database Name: databasedb
Username: databasedb
Password: password
I am hosting on a GoDaddy account that only allows a single MS SQL database. In development I had two separate databases; one was ASPNETDB.MDF and the other was Database.MDF. Do I also need to have two separate databases in the hosted environment?
I forgot to mention that yes, GoDaddy does provide a configuration string. I have been trying for two days to make it work without success which is why I am posting here.
The string provided by GoDaddy is:
Data Source=somesource.com; Initial Catalog=databasedb;User ID=databsedb; Password=password;
Also, if necessary I can upgrade my GoDaddy account and get another database. Which I am willing to do if it will make my life easier.

Go Daddy gives you a connection string that you can copy and paste into your web.config that is specific to your database once you set it up. You would just need to make sure you keep the name property the same and you shouldn't have any problems (as long as the DB schema is the same as well).
If you have two databases that you are accessing in your code, you either need to combine them or use two in the hosted environment. Why two in the first place? Is one for the asp.Net users and roles and the other for site data? If that's the case, I would combine them and change my site code to use one connection string.

For your limitation with only one sql database with godaddy one option will be to consolidate your two databases in one.
About the connection strings if you're using visual studio 2010 there's a new feature that allows to make transformations in the web.config based on the build settings so you can have a development and production settings that will transform the web.config automatically. You can find more information about that here, http://www.hanselman.com/blog/WebDeploymentMadeAwesomeIfYoureUsingXCopyYoureDoingItWrong.aspx
If vs 2010 is not an option then one solution can be to have an application key in your web.config , something like enviroment="development" and then in code when connecting to the database choose the appropiate connection string based on that application setting.

No need to upgrade the plan from Go Daddy or even do not buy extra Database. You can do like, you merge two databases into single database. All the tables from second database will be under first database. Then you can use only one connection string for your multiple applications hosted on same server or different server.

Related

Proper format for SQL Server Connection String on 1and1.com

I have spent several hours trying to search this on the web in addition to calling and emailing support at 1and1.com web hosting with no success.
I have ASP.NET pages which connect to MS SQL Server database using the entity framework. On my local machine, all works fine (naturally). However, when I modify the connection string in my web.config to point to my SQL Server database on 1and1.com, I get the following error:
"Unable to load the specified metadata resource."
Here's my current connection string (as defined in my web.config file):
<add name="TimeDataLicenseEntities"
providerName="System.Data.EntityClient"
connectionString="metadata=res://*/
Model1.csdl|res://*/
Model1.ssdl|res://*/
Model1.msl;
provider=System.Data.SqlClient;
provider connection string="
data source=dbXXXX.db.1and1.com,1433;
Integrated Security=false;
initial catalog=database_name;
user id=dboXXXX;
password=valid_password;multipleactiveresultsets=True"" />
(Please note that where there are 'XXXX' the values are different in the actual config file as well as for 'database_name' and 'valid_password')
I'm using the Entity Framework in the code so I'd prefer solutions that correct the content of my web.config file.
Here is what ended up working for me:
<add name="TimeDataLicenseEntities"
providerName="System.Data.EntityClient"
connectionString="metadata=
res://<assemblyname>/Model1.csdl|
res://<assemblyname>/Model1.ssdl|
res://<assemblyname/Model1.msl;
provider=System.Data.SqlClient;
provider connection string="
data source=dbXXXX.db.1and1.com,1433;
Integrated Security=false;
initial catalog=database_name;
user id=dboXXXX;
password=valid_password;
multipleactiveresultsets=True"" />
By including the assemblyname for my code in the sections above (the brackets ('<' and '>') should not be included), I was able to finally get it to work.
Thanks all for your assistance.
Here is what actually works on 1and1 server from ASP.NET Code first design. So, simply replace your serverName, DatabaseName, UserID, and Password.
<add name="DefaultConnection"
connectionString="Data Source=dbXXX.db.1and1.com,1433;Initial Catalog=dbYYYYY;Integrated Security=False;user id=dboZZZZZ;password=YOURDBPASSWORD;MultipleActiveResultSets=True;Application Name=EntityFramework"
providerName="System.Data.SqlClient" />
Hope this can help anyone looking to use 1and1 asp.net server since their customer service is pretty useless.

how can i connect to database from IIS 5.1

When I want to connect to my site database via the local networkŘŚ This message will appear:
Cannot log in to my_server_name/AspNet
My connection string is:
<connectionStrings>
<add name="behbahan_cementConnectionString" connectionString="Data Source=MAYA-1307F9F334\SQLEXPRESS;Initial Catalog=behbahan_cement;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>`
I can't connect to the database?
I'd suggest you first try and establish whether you can connect to the database from outside the web application either via SQL Server Management Studio or by using a .UDL file. I've answered a question on testing a SQL server connection here.
Based on the results of these tests it may become apparent to you what the problem may be. In your case, you are using integrated security (which you would need to be on a domain to use over the network). If you are not on a domain, a username and password may need to be supplied.
Standard way to connect Database as;
<connectionStrings>
<add
name="NorthwindConnectionString"
connectionString="Data Source=serverName;Initial
Catalog=Northwind;Persist Security Info=True;User
ID=userName;Password=password"
providerName="System.Data.SqlClient"
/>
</connectionStrings>
What I can See here is you are messing ;
ID=userName;Password=password"
to connect the database in connectionString. Default username and password should be "root" unless you have changed it.
Try to connect with this detail.
Thanks,

asp.net connection string issue (database is on server side)

I need to connect to server database, hosting support gave me data how to connect:
server=176.9.119.68,3333\sqlexpress;Database=;User ID=;Password=
Right now I created new website (file->new website->asp.net website) and added new item to project (right click -> add new item -> sql server database).
and right now I have connection string:
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
what do I need to do to connect to server database: I need to change connection string or I need to change some steps in adding database.
P.S. After I add database, I need to add ado.net entity frameword to connect to this database (I know how to do this when database is inside my project , but may there will be extra steps when database is on the server side?)
Simply replace the existing connection string with your providers one. To test, you can use Sql Management Studio to connect to that server. If gets connection then you can work with remote database in your local projects. Below is the connection string. We too work on similar fashion, for websites and small web based applications. But for enterprise application we prefer Local Development Servers.
<connectionStrings>
<add name="ApplicationServices"
connectionString="server=176.9.119.68,3333\sqlexpress;Database=*******;User ID=******;Password=*****"
providerName="System.Data.SqlClient" />
</connectionStrings>

SQL Server connection string woes

After spending 6 hours today to get a connection with my SQL Server 2012 database from Visual Studios 2012, I give up.
Setup:
Database: App_Data/GameDB.mdf
DB Location: C:\Users\USERNAME\Documents\Visual Studio 2012\Projects\ProjectRawWar\ProjectRawWar\App_Data\GameDB.mdf
Connection string:
<add name="LocalSqlServer"
connectionString="Data Source=(LocalDB)\v11.0;Initial Catalog=GameDB;Integrated Security=False;"/>
I first tried a SQL Server Compact database, didn't work.
I tried many other connection strings from connectionstrings.com, didn't work.
I tried to put the full path of the database in the connection string, didn't work.
Can someone please help me out of my misery?
Update:
I just followed http://msdn.microsoft.com/en-us/library/aa983322.aspx.
The database is there. I copied the connection string from the wizard right into my webconfig connectionstring, still doesnt work. Why? Where is the logic?
Reading your question I am getting the feeling that you are trying to connect to a database file. While you can do that with Access "Databases" it is not possible with SQL Server databases. The file needs to be mounted or attached to SQL Server first.
Check out this MSDN article for details: http://msdn.microsoft.com/en-us/library/ms190209.aspx#SSMSProcedure
If you're going to disable integrated security, then you need to provide a username and password.
IE:
Server=127.0.0.1;User ID=useridhere;Password=passwordhere;database=dbnamehere
Be sure to make sure the userid and password you specify has access to the database you need. For testing, you can use the 'sa' account, but that's a poor long-term solution for major security reasons.
Ok I fixed it myself.
How I did it:
Delete every .sdf and .mdf file.
Just made following connection strings:
`<add name="DataContext"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\GameDB1.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="LocalSqlServer"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\GameDB1.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />`
Visual Studio created my database using my DBContext.
Thanks all for the information.

ASP.NET EFCodeFirst not using correct connection string

I am trying to publish a website using ASP.NET MVC3 EF and CODEFIRST with a SQL Server 2008 backend. On my local machine I was using a sql express db for development, but now that I am pushing live, I want to use my hosted production database. The problem is that when I try to run the application, it is still using my local db connection string. I have completely removed the old connection string from my web.config file and am using the <clear /> tag before creating the new connection string. I have also cleaned the solution and rebuilt, but somehow it is still connecting to the old db. What am I missing?
This is the new connection string:
<connectionStrings>
<clear />
<add name="CellularAutomataDBContext"
connectionString=" Server=XXX;
Database=CellularAutomata; User ID=XXX; Password=XXX; Trusted_Connection=False"
providerName="System.Data.SqlClient" />
</connectionStrings>
UPDATE
When I debug and look at the DBCONTEXT object, this is what is showing up for its connection:
Data Source=.\\SQLEXPRESS;Initial Catalog=CellularAutomata.Models.D1K2N3CARuleDBContext;Integrated Security=True;MultipleActiveResultSets=True"
I am unsure why this is happening because I cannot find it being set to this anywhere. Also, under configuration it says LazyLoadingEnabled = true, I assume this may be part of the problem, maybe it is not loading the new connection string. Where do I change these parameters?
UPDATE 2
EFCodeFirst is using a default connection string, I can't figure out how to get it to accept the connection string that I specify in the web.config file.
So, When using EF CodeFirst, there is a default connection string that it uses. If you want to be able to use a custom connection string, there are a few parameters guidelines that you must follow.
name ="this must match the name of your database context class"
connectionString="Server=yourserverurl; Database=yourdatabasename; User ID=youruserid;
Password=yourpassword; Initial Catalog=the name of the database to use;
Trusted_Connection=False"
providerName="System.Data.SqlClient"
So far this is working for me.
The connectionString you show is not an EF connection string. The EF won't use it. So you're changing the wrong thing.
An EF connectionString will include providerName="System.Data.EntityClient"
It will look for the same name as your context and depending on what else you
are using other names as well. I usually use the following for controlling
specific features with either the same or specific connection strings
(I keep app services in a different db for example so EFCF can drop tables as needed):
<connectionStrings>
<add name="MyAppContext" .../>
<add name="ApplicationServices" .../>
<add name="DefaultConnection" .../>
</connectionStrings>

Resources