connection string issue after hosting website - asp.net

Please help me with this!
I've put my website on somee.com, they gave this connection string
Connection string: workstation id=GWAPDataBase.mssql.somee.com;packet size=4096;user id=xxxx;pwd=xxxxx;data source=GWAPDataBase.mssql.somee.com;persist security info=False;initial catalog=GWAPDataBase
and my auto generated connection string when i was on local host was
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<add name="GWAP_Entities" connectionString="metadata=res://*/App_Code.GWAPModel.csdl|res://*/App_Code.GWAPModel.ssdl|res://*/App_Code.GWAPModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\aspnetdb.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
I tried to modify it, but I get an error that says
The specified named connection is either not found in the
configuration, not intended to be used with the EntityClient provider,
or not valid.
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: The specified named
connection is either not found in the configuration, not intended to
be used with the EntityClient provider, or not valid.
Source Error:
Line 19: #region Constructors Line 20: Line 21: public
GWAP_Entities() Line 22: : base(ConnectionString,
ContainerName) Line 23: {
Please help me how should I modify the connection string?

It sounds like your connection string name and the name that the Entity Framework expects do not match. Without more information about how your code looks, I am assuming that you generated your models from the database using the wizard in Visual Studio. When you do that, you enter a name for the connection string which then gets hard-coded in your designer file. An example:
public FooEntity() : base("name=FooEntity", "FooEntity")
{
this.ContextOptions.LazyLoadingEnabled = true;
OnContextCreated();
}
The string "FooEntity" in this case would need to be the name of the connection string. If they are different, a connection string won't be found. Make sure those values match.

Related

Web deployment task failed

I'm getting this error when I click Build Deployment Package.
I've read a bunch of related post regarding this issue but doesn't seems to answer the questions on my mind T_T.
This is my connection string on my Web.Config
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<add name="ProjectPALEntities" connectionString="metadata=res://*/Models.ProjectPal.csdl|res://*/Models.ProjectPal.ssdl|res://*/Models.ProjectPal.msl;provider=System.Data.SqlClient;provider connection string=';data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\ProjectPAL.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework';" providerName="System.Data.EntityClient" />
</connectionStrings>
This is Package/Publish SQL Settings Under Project Properties. This is where I'm having a problem.
This is the connection string for the source database above.
data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\ProjectPAL.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework';
QUESTIONS:
In the Connection string for the source database which is the correct one to use?
data
source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\ProjectPAL.mdf;integrated
security=True;user
instance=True;multipleactiveresultsets=True;App=EntityFramework'; (this one is what I'm currently using)
metadata=res:///Models.ProjectPal.csdl|res:///Models.ProjectPal.ssdl|res://*/Models.ProjectPal.msl;provider=System.Data.SqlClient;provider
connection string=';data
source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\ProjectPAL.mdf;integrated
security=True;user
instance=True;multipleactiveresultsets=True;App=EntityFramework'; (with metadata or none of the above T_T)
Where could I get the Connection string for destination database? Sorry It's my first time to deploy a website. I researched but I can't find an answer T_T.
How could I possibly fixed this error?
Other Informations:
I changed &quot with ' (single quote) after reading this reference Explicit connection string for EF
I'm using Membership Provider and Role Provider and all my data is saved in ProjectPALEntities
If you need more Info just tell me. :)
Ok here's what I did.
I checkout new application from my repository and repeat every steps I did. When I click Import from web.config it automatically created this connection string for me under Connection string for source database.
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ProjectPAL.mdf;Integrated Security=True;Application Name=EntityFramework;User Instance=True
for the Connection string for destination database I just leaved it blank because I dunno what to put there.
When I clicked Build Deployment Package the error message doesn't shows anymore.
I wish I knew what to put ont the Connection string for destination database T_T

The entity type is not part of the model for the current context

My ASP.NET application is working locally, but when I deploy it, I get the following error: "The entity type Usuario is not part of the model for the current context". I've tried every solution I found, but I couldn't get it work.
I think it can be something wrong in connection string because they are different ones to local database and remote database. This is the connection string in Web.Release.config file:
<add name="ModelContainer" connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider connection string="Data Source = tcp:ebmzszqsw8.database.windows.net,1433; Initial Catalog = {database_name}; User ID = {my_id}; Password={my_password};Trusted_Connection=False;Encrypt=True;Connection Timeout=30"" providerName="System.Data.EntityClient" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />

Why is the SPA application not creating a database?

I have followed a microsoft video trying to make the single page application and it doesnt create or connect to my sql instance even though I have other applications using code first. For example the connection string was...
<add name="DefaultConnection" connectionString="Data Source=Localhost;Initial Catalog=aspnet-MvcApplication2-201265113324;Integrated Security=True" providerName="System.Data.SqlClient" />
But I get an error saying
A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: SQL
Network Interfaces, error: 26 - Error Locating Server/Instance
Specified)
Its really strange because my other application with the connectionstring...
<add name="PteDotNetContext" providerName="System.Data.SqlClient" connectionString="Server=Localhost;Database=PteDotNet;Trusted_Connection=true;" />
Works fine and will connect no problem...
If you do not provide a connection string or connection string name to the DbContext constructor, it will try to find a connection name that matches the (inherited) DbContext class name.
Hence you can either change the name of the connection string
<add name="MyDbContext" connectionString="Data Source=Localhost;Initial Catalog=aspnet-MvcApplication2-201265113324;Integrated Security=True" providerName="System.Data.SqlClient" />
Or provide the name of the connection string in the constructor
public class MyDbContext : DbContext
{
public MyDbContext() : base("DefaultConnection") {}
}

Connection string error using membership provider from WCF service

The target is: I need a wcf method which will create user in the database.
I am using membership provider. and My client is SmartPhone/mobile device.
I wrote a method which will create user BUT when I test the method I get the following error.
error:
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
And I get this error in the following line:
Membership.CreateUser(name, password,email,"question","answer",true,out createStatus);
I am using the same connectionString that I use to read data from the database.
My connection string is:
<add name="MajangoEntities" connectionString="metadata=res://*/EntityModel.MajangoEntityModel.csdl|res://*/EntityModel.MajangoEntityModel.ssdl|res://*/EntityModel.MajangoEntityModel.msl;provider=System.Data.SqlClient;provider connection string="data source=tcp:sql2k298.discountasp.net;initial catalog=SQL2008R2_835021_myddb;user id=SQL2008R2_835021_mydb_user;password=mypassword;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Can anybody help me with some ideas??
That connection string includes some Entity Framework specific data. Try instead just the "provider connection string" embedded within it:
<add name="MajangoEntities" connectionString="data source=tcp:sql2k298.discountasp.net;initial catalog=SQL2008R2_835021_myddb;user id=SQL2008R2_835021_mydb_user;password=mypassword;multipleactiveresultsets=True;App=EntityFramework">
The rest of the data in there (the metadata, etc.) is just confusing SQL Server.

Connection String

I have a asp.net application.there is a databinding section to a datagrid.But there have an error.I think it may be in web config-Connection string.
Connection String is like this
<add name="ArchitectConnectionString" connectionString="Data Source=192.168.1.15,1433;Network Library=DBMSSOCN;Initial Catalog=Architect;" providerName="System.Data.SqlClient" />
the error is
Login failed for user ''. The user is not associated with a trusted SQL Server connection.
Please help me..
You need to specify a username/password to the end of the connection string,
";User ID=UserName;Password=Password"
Or if you are using Windows Auth then
"Integrated Security=True"
The connection string is expecting a user id and password add the following string to the end of the connection string:
String to add:
Userid=myUserID;Password=!12345
Complete altered string example:

Resources