web.config connectionStrings on production server - asp.net

I'm attempting to deploy my first website containing a database. The test local version has the following connection strings
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;IntegratedSecurity=SSPI;
AttachDBFilename=|DataDirectory|\aspnetdb.mdf;
User Instance=true"
providerName="System.Data.SqlClient" />
<add name="ConnectionString"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\AHData.mdf;IntegratedSecurity=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
I've setup the databases on the web hosting company server and they give me the following connections strings
Provider=sqloledb;Data Source=db479427514.db.1and1.com,1433;Initial Catalog=db479427514;User Id=dbo479427514;Password=****;
Provider=sqloledb;Data Source=db479427535.db.1and1.com,1433;Initial Catalog=db479427535;User Id=dbo479427535;Password=****;
When I replace the local test connection strings with the new server ones using
<connectionStrings>
<add name="ApplicationServices"
connectionString="Provider=sqloledb;Data Source=db479427535.db.1and1.com,1433;Initial Catalog=db479427535;User Id=dbo479427535;Password=**I've used real password!**;"
providerName="System.Data.SqlClient" />
<add name="ConnectionString"
connectionString="Provider=sqloledb;Data Source=db479427514.db.1and1.com,1433;Initial Catalog=db479427514;User Id=dbo479427514;Password=**I've used real password!**;"
providerName="System.Data.SqlClient" />
</connectionStrings>
I get the following error
Keyword not supported: 'provider'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Keyword not supported: 'provider'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
[ArgumentException: Keyword not supported: 'provider'.]
[ArgumentException: An error occurred while attempting to initialize a System.Data.SqlClient.SqlConnection object. The value that was provided for the connection string may be wrong, or it may contain an invalid syntax.
Parameter name: connectionString]
Can anyone advise what is wrong here?

Try removing the 'provider' section of the connection string:
<add name="ApplicationServices" connectionString="Provider=sqloledb;Data Source=db479427535.db.1and1.com,1433;Initial Catalog=db479427535; User Id=dbo479427535;Password=**I've used real password!**;" providerName="System.Data.SqlClient" />
becomes
<add name="ApplicationServices" connectionString="Data Source=db479427535.db.1and1.com,1433;Initial Catalog=db479427535;User Id=dbo479427535;Password=**I've used real password!**;" providerName="System.Data.SqlClient" />
Because the provider name is specified in it's own name-value pair (providerName=) I doubt it would be needed in the connection string. Give it a crack and report back.

Correct your Connecting sting to:
<connectionStrings>
<add name="ApplicationServices" connectionString="
Data Source=db479427535.db.1and1.com,1433;Initial Catalog=db479427535;
User Id=dbo479427535;Password=**I've used real password!**;"
providerName="System.Data.OleDb" />
<add name="ConnectionString" connectionString="
Data Source=db479427514.db.1and1.com,1433;Initial Catalog=db479427514;
User Id=dbo479427514;Password=**I've used real password!**;"
providerName="System.Data.OleDb" />
</connectionStrings>
This is because we dont have provider object in connection string, so remove that and specify the provider name under "providerName" section of connection string to: System.Data.OleDb

Related

Connection Strings- smarterasp.net

Can anyone help me with this? Ive been getting tons of errors. I know there's probably just a syntax error here somewhere, but I'm not sure if I'm doing it right.
this is the connection string that was given to me by smarterasp: "Data Source=SQL5006.Smarterasp.net;Initial Catalog=DB_9B7F44_capstone;User Id=DB_9B7F44_capstone_admin;Password=YOUR-PASSWORD;"
this was my connection string on my local machine:
<connectionStrings> <add name="d_CapstoneEntities1" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=WIN-C43BMU8UF5E\SQLEXPRESS;initial catalog=d_Capstone;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
and then I came up with this, but im still getting the error "Keyword not supported: 'data source'."
<add name="d_CapstoneEntities1" providerName="System.Data.EntityClient" connectionString="Data Source=SQL5006.Smarterasp.net;Initial Catalog=DB_9B7F44_capstone;User Id=DB_9B7F44_capstone_admin;Password=YOUR-PASSWORD;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework;"/></connectionStrings>
I used the EF database first btw.

Entity Framework connection string issue

I am receiving the following error which I believe is a problem with my connection string on GoDaddy. I've copied from an example on Stack Overflow, but it doesn't seem to work. The first part of the stack trace that I'm getting is:
[MetadataException: Unable to load the specified metadata resource.]
System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(String
assemblyName, String resourceName, ICollection`1 uriRegistry,
MetadataArtifactAssemblyResolver resolver) +2184231
I have a solution with only one project and, of course, the edmx is in that project.
Here is my connection string:
<add name="FCGUIDE_Entities"
connectionString="
metadata=res://*/CoreModel.csdl|res://*/CoreModel.ssdl|res://*/CoreModel.msl;
provider=System.Data.SqlClient;
provider connection string='
Data Source=susanbfarrar.db.9319451.hostedresource.com;
Initial Catalog=susanbfarrar;
integrated security=False;
multipleactiveresultsets=True;
App=EntityFramework;
User ID=*****;
Password=*****
Database=*****;'"
providerName="System.Data.EntityClient" />
Could you replace ' with " and try it again?
<add name="FCGUIDE_Entities"
connectionString="
metadata=res://*/CoreModel.csdl|res://*/CoreModel.ssdl|res://*/CoreModel.msl;
provider=System.Data.SqlClient;
provider connection string="
Data Source=susanbfarrar.db.9319451.hostedresource.com;
Initial Catalog=susanbfarrar;
integrated security=False;
multipleactiveresultsets=True;
App=EntityFramework;
User ID=*****;
Password=*****
Database=*****;""
providerName="System.Data.EntityClient" />
You already have Initial Catalog, so remove Database
Password=*****Database=*****;"
Like this -
Password=*****;"

Switching asp.net connection strings live/test/dev

We have a different set of connection strings in our config file as follows.
<!-- TEST CONNECTION STRING -->
<!--
<add name="fooConnection" connectionString="Data Source=Test_server;Initial Catalog=foo_dbTEST;User ID=foo_user;Password=abc1234;"/>
<add name="barConnection" connectionString="Data Source=Test_server;Initial Catalog=bar_dbTEST;User ID=bar_user;Password=abc1234;"/>
<add name="chewConnection" connectionString="Data Source=Test_server;Initial Catalog=chew_dbTEST;User ID=chew_user;Password=abc1234;"/>
-->
<!-- LIVE CONNECTION STRING -->
<add name="fooConnection" connectionString="Data Source=Live_server;Initial Catalog=foo_dbTest;User ID=fooTest_user;Password=abc1234;"/>
<add name="barConnection" connectionString="Data Source=Live_server;Initial Catalog=bar_Testdb;User ID=barTest_user;Password=abc1234;"/>
<add name="chewConnection" connectionString="Data Source=Live_server;Initial Catalog=chew_Test;User ID=chewTest_user;Password=abc1234;"/>
<!-- Local DEV CONNECTION STRING -->
<!--
<add name="fooConnection" connectionString="Data Source=MyDoombaPC;Initial Catalog=fooDEVdbTest;User ID=foouser;Password=abc1234;"/>
<add name="barConnection" connectionString="Data Source=MyDoombaPC;Initial Catalog=barDEVdb;User ID=barTestuser;Password=abc1234;"/>
<add name="chewConnection" connectionString="Data Source=MyDoombaPC;Initial Catalog=chewDEVdb;User ID=chewuser;Password=abc1234;"/>
-->
When I need to change from, for example, live to test I move the XML comments from the Test section to the live section. Is there a more elegant way of doing this using Visual Studio 2010?
Just to be clear this is not a requirement of the application once it is in production, this is for developers to switch between different database connection string sets.
How do others approach this?
You could use the web.config transformation : web.config Transformation
This will allow you to have seperate config files for both debug and release and have different setting in each.

configuring web.config for deployment with GoDaddy hosting

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.
UPDATE:
I changed connection strings to this:
<add name="ApplicationServices" connectionString="data source=leqaspnetdb.db.8311806.hostedresource.com;Initial Catalog=leqaspnetdb;User ID=leqaspnetdb; Password=Dan13206" providerName="System.Data.SqlClient" />
<add name="ConnectionString" connectionString="Data Source=leqaspnetdb.db.8311806.hostedresource.com;Initial Catalog=leqaspnetdb;User ID=leqaspnetdb; Password=Dan13206" providerName="System.Data.SqlClient" />
<add name="DatabaseConnectionString" connectionString="Data Source=leqaspnetdb.db.8311806.hostedresource.com;Initial Catalog=leqaspnetdb;User ID=leqaspnetdb; Password=Dan13206" 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=leqaspnetdb.db.8311806.hostedresource.com;
Initial Catalog=leqaspnetdb;User ID=leqaspnetdb;Password=Dan13206;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
And I get this error:
Illegal characters in path.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Illegal characters in path.
You can certainly use one database in your hosted environment as long as there are no schema conflicts.
You can have multiple connectionStrings in web.config pointing to the same database.
Here is an example connection string for discountasp.net hosting (sorry have nothing with goDaddy).
<add name="TestDiscountAspNet"
connectionString="Data Source=xxx.discountasp.net;Initial Catalog=SQL2008R2_837232_yyy;
Persist Security Info=True;MultipleActiveResultSets=True;User ID=myUserName;Password=myPassword"
providerName="System.Data.SqlClient"/>
If you still have any problem, please describe what the problem is.
Below is documentation on Godaddy about connecting to its database:
(http://support.godaddy.com/help/article/256/connecting-to-a-microsoft-sql-server-database-using-aspado?locale=en&ci=4606)
This example describes using ASP/ADO to connect to a Microsoft SQL Server Database.
Replace the db_ fields with the information for your database from the Control Panel in your hosting account. For more information, see Locating Your MS SQL Database Connection Strings for more information.
<%
'Sample Database Connection Syntax for ASP and SQL Server.
Dim oConn, oRs
Dim qry, connectstr
Dim db_name, db_username, db_userpassword
Dim db_server
db_server = "whsql01.mesa1.secureserver.net"
db_name = "your_dbname"
db_username = "your_dbusername"
db_userpassword = "your_dbpassword"
fieldname = "your_field"
tablename = "your_table"
connectstr = "Driver={SQL Server};SERVER=" & db_server & ";DATABASE=" & db_name & ";UID=" & db_username & ";PWD=" & db_userpassword
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open connectstr
qry = "SELECT * FROM " & tablename
Set oRS = oConn.Execute(qry)
Do until oRs.EOF
Response.Write ucase(fieldname) & ": " & oRs.Fields(fieldname)
oRS.MoveNext
Loop
oRs.Close
Set oRs = nothing
Set oConn = nothing
%>

Enterprise library 4 dataconfiguration tag

I am using Enterprise library for my data access.
When I am running the application, at the CreateDatabase() statement I am getting this exception:
Microsoft.Practices.ObjectBuilder2.BuildFailedException
was unhandled by user code
Message="The current build operation
(build key Build
Key[Microsoft.Practices.EnterpriseLibrary.Data.Database,
null]) failed:
The value can not be null or an empty string.
(Strategy type Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy,
index 2)"
Source="Microsoft.Practices.ObjectBuilder2"
Now, I googled a bit and I found that I have to place
<dataConfiguration defaultDatabase="LocalSqlServer"/>
but I don't know where. Is it the right solution?
Also, at the time of installing enterprise library I didn't see any connection string statement? So, I wonder how it will take the connection string from web.config file.
In the connection string section of my web.config file I have:
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=MSTR;Initial Catalog=USERDb;Integrated Security=true;" providerName="System.Data.SqlClient"/>
Yes you need to add the dataConfiguration section to the web.config.
First you need to add dataConfiguration to the list of ConfigurationSections in your web.config:
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</configSections>
Then you need to add your connection strings to the web.config (you've already done this):
<connectionStrings>
<add name="LocalSqlServer" connectionString="Data Source=MSTR;Initial Catalog=USERDb;Integrated Security=true;" providerName="System.Data.SqlClient"/>
</connectionStrings>
Then you need to add the actual dataConfiguration section to the web.config:
<dataConfiguration defaultDatabase="LocalSqlServer"/>
You can also use the Enterprise Library Configuration Tool to do this for you as well.

Resources