Simple Membership Configuration with default connection - asp.net-mvc-4

how do you configure your MVC4 application to use an entity framework connection string which already exists to use for its default connection with conjunction with the simplemembership provider tables etc on an existing SQL server database. Im sure ive achieved this before but with a new internet template mvc4 solution i seem unable.
i am configuring this line in InitializeSimpleMembershpAttiribute
WebSecurity.InitializeDatabaseConnection("myEntitiesConnstring","mytable", "UserId", "full_name", autoCreateTables: true);
I can get a combination of either
"Unable to find the requested .Net Framework Data Provider. It may not be installed.
if i leave this section alone
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
or
Format of the initialization string does not conform to specification starting at index 0
with
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
If i comment out the defaultconnectionlibrary i get.
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)
This entityframework connection string is valid and does connect to the database correctly. In all the 3 above scenarios i get no activity however if i use sql profiler to trace the activity.
(Connectionstring)
<connectionStrings>
<add name="myEntitiesConnstring" connectionString="metadata=res://*/Models.my_Model.csdl|res://*/Models.my_Model.ssdl|res://*/Models.my_Model.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=mydb;persist security info=True;user id=sa;password=password;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
cheers
tim
p.s.Jon Galloway's article suggestions dont seem to be helping me

Related

MVC Entity framework from local database to SQL database Azure

Possibly a very simple question, but it has already taken me several days. The problem:
In my project, MVC Entity framework, and on my local computer it connects with a local database and that works as expected. I can add items to the database and remove its etc. At azure, I have a SQL database and when I deploy the project to azure I get the following error message
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: 52 -
Unable to locate a Local Database Runtime installation. Verify that SQL
Server Express is properly installed and that the Local Database Runtime
feature is enabled.)]
I ques that the my connection string is incorrectly and my application can't connect to the azure SQL database. I tried to add and change the connection string, but somehow I can't make it work. This is what I have (minus password and username) :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings><add name="InventoryEntities" connectionString="metadata=res://*/Administration.csdl|res://*/Administration.ssdl|res://*/Administration.msl;provider=System.Data.SqlClient;provider connection string="Server=tcp:****.database.windows.net,1433;Initial Catalog=****;Persist Security Info=False;User ID=****;Password=****;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"" providerName="System.Data.EntityClient" /></connectionStrings>
</configuration>
What am I doing wrong?
After a night sleep, I finally got it working.First of all, I had to make clear which database I was going to be use where the DbContext was initialized
public class EFDbContext : DbContext
{
public EFDbContext() : base("name=InventoryEntities")
{
}
}
With InventoryEntities being the name of the connectionstring in the web.config of the WebUI which I did not change.
Simple as that, but it took days......

Failed login for user

I'm developing a website for sharepoint using asp.net, it is connected to a database. In visual studio server explorer, the database is accessible using a new sql user I created. I granted sysadmin permissions to that user. However, when I deploy the site and run it, it gives me this error 'login failed for user'.
The sql server is configured to allow mixed authentications. I restarted the server, I played with the user permissions but nothing ever changed.
The connection string I got it from server explorer which I'm sure it is correct:
Data Source=servertest;Initial Catalog=qDB;User ID=me2;Password=***********"
What should I do? I've tried every possible solution I found on google and I ended up here.
Try like this by editing your connection string:-
Server=myServerAddress;Database=myDataBase;User Id=myUsername; Password=myPassword;
I too had same scenario this worked for me
<connectionStrings>
<add name="connectionstring" connectionString="Data Source=XYZ\SHAREPOINT;Initial Catalog=DBName;Integrated Security=true;" providerName="System.Data.SqlClient" />
</connectionStrings>
You can Use connection string like this
<appSettings>
<add key="KhadamatConnectionString"
value="Server=[copy name from Your ServerName of SSMS];Database=AcaService;uid=admin;pwd=mypass;" />
</appSettings>
or
<connectionStrings>
<add name="KhadamatConnectionString" connectionString="Data Source=[copy name from Your ServerName of SSMS];Initial Catalog=AcaService;User ID=admin;Password=mypass;" providerName="System.Data.SqlClient"/>
</connectionStrings>

how to handle database reallocation for dotnetnuke website

i have a website that used to run on sqlexpress data base i changed my server and it stopped running i ran it using visual studi and IIS but it eith gives me error 404 or error 503 i think the problem is in my webconfig sql string connection her is my code:
<connectionStrings>
<add name="SiteSqlServer" connectionString="Data Source=localhost;Initial Catalog=ULTRA; User ID=admin;Password=123" providerName="System.Data.SqlClient" />
<add name="SiteSqlServer" connectionString="Server=(local);Database=DotNetNuke;uid=;pwd=;" providerName="System.Data.SqlClient" />
-->
<!-- Connection String for SQL Server 2008/2012 Express -->
<!--<add name="SiteSqlServer" connectionString="Data Source=localhost;Initial Catalog=ULTRA; User ID=admin;Password=123" providerName="System.Data.SqlClient" />-->
<!-- Connection String for SQL Server 2008/2012
-->
<!--<add name="SiteSqlServer" connectionString="Server=(local);Database=DotNetNuke;uid=;pwd=;" providerName="System.Data.SqlClient" />-->
</connectionStrings>
<appSettings>
<!-- Connection String for SQL Server 2008/2012 Express - kept for backwards compatability - legacy modules -->
<!--<add key="SiteSqlServer" value="Data Source=.\SQLExpress;AttachDbFilename=|DataDirectory|Database.mdf;Integrated Security=True;User Instance=True" />-->
<!-- Connection String for SQL Server 2008/2012 - kept for backwards compatability - legacy modules
-->
<add key="SiteSqlServer" value="Server=(local);Database=DotNetNuke;uid=;pwd=;" />
would someone please help me to tell me what is wrong?
You have your connection string defined multiple times in the ConnectionStrings section of the web.config. Which is the proper connection string?
EDIT:
You likely have an issue with the PortalAliases and your IIS configuration. What is the URL that you are trying to access the website using? Make sure that URL is listed in the PortalAliases table, also make sure that IIS will respond to the URL as well.

Role provider not working with SQL Server Enterprise

I am getting the following error,
The user instance login flag is not supported on this version of SQL Server. The connection will be closed.
from the below line of code in my razor view(MVC5)
#if(Roles.IsUserInRole("User"){}
I have upgraded my database sql server from Express 2012 to Enterprise 2012 edition . After that I got above error. Since my application is EF code-first, database is created automatically but role provider doesn't seem to be working.
<add name="Foo" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Foo_db;User ID=sa;Password=******" providerName="System.Data.SqlClient" />
Check out this thread. It should help.
http://forums.asp.net/t/1939748.aspx
I have tested this, User.IsInRole is now working for me. Make sure you have this in your Startup class
Did you remember to put the application name in your web config?
<roleManager enabled="true">
<providers>
<clear />
<add connectionStringName="ApplicationServices"
name="AspNetSqlRoleProvider"
type="System.Web.Security.SqlRoleProvider"
applicationName="DONT FORGET THIS PART" />
</providers>
</roleManager>

NServiceBus SqlTransport - Where timeout manager should be run?

We are currently setting up NServiceBus with SqlTransport. Do we need use distributors in our test environment ? We have 2 clustered node are running the same application. Where timeout manager should be run in this scenario ?
The distributor is only used for MSMQ transport, see http://particular.net/articles/load-balancing-with-the-distributor section "When to use it?".
Updated:
Timeout manager runs on all endpoints connecting to the same sql database as the transport to avoid DTC.
Here is an example config:
<connectionStrings>
<add name="NServiceBus/Transport" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=nservicebus;Integrated Security=True" />
<add name="NServiceBus/Persistence" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=nservicebus;Integrated Security=True" />
</connectionStrings>
You need to reference NserviceBus.NHibernate, see http://particular.net/articles/relational-persistence-using-nhibernate---nservicebus-4.x for more info.