Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing default connection string for Membership, Roles, etc

By default, it seems like my web application is using LocalSqlServer as the connection string to use for any application services such as Membership/Roles/Authentication/etc.

Is there any way I can change what the default connection string should be? It seems so arbitrary that the default is "LocalSqlServer" and the only way I was able to find this was by googling for this for about two hours.

I don't want to be forced to have to name my server connection "LocalSqlServer" and I have no idea if this is a preexisting item that I might be overwriting.

like image 263
Mike Bailey Avatar asked Nov 24 '11 00:11

Mike Bailey


People also ask

How do I change my connection string?

Select the TableAdapter or query that has the connection you want to edit. In the Properties window, expand the Connection node. To quickly modify the connection string, edit the ConnectionString property, or click the down arrow on the Connection property and choose New Connection.

How do I change the connection string after deployment?

If you save your connection string in the udl file, the user can change the connection via an interface by simply double clicking that file. You can set your connection string in the app to point to the udl file. You can also launch the udl interface programmatically if you want.

What is connection string in app?

Applications use connection strings to identify the server instance and database to connect to and to determine what driver, login, etc. to use to connect to the SQL Server instance. Typically, the connection string will be stored in a configuration file somewhere within the application or web server.


2 Answers

Yes, these connection strings can be set in web.config:

Membership

<membership defaultProvider="SqlMembershipProvider">
  <providers>
      <add 
        name="SqlMembershipProvider" 
        type="System.Web.Security.SqlMembershipProvider" 
        connectionStringName="MyMembershipConnectionString"
       />
  </providers>
</membership>

Roles

<roleManager defaultProvider ="SqlRoleProvider" >
   <providers>
     <add
       name="SqlRoleProvider" 
       type="System.Web.Security.SqlRoleProvider" 
       connectionStringName="MyRolesConnectionString"
     />
   </providers>
</roleManager>

See here for more info: How to: Use the ASP.NET Membership Provider

like image 135
Chris Fulstow Avatar answered Sep 22 '22 20:09

Chris Fulstow


2 things. Look for, or add a "connectionStringName" property in your membership config.

Here is an example that uses it

<system.web>
 ...
 <membership defaultProvider="MembershipADProvider">
  <providers>
    <add
      name="MembershipADProvider"
      type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, 
            Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
                connectionStringName="YOUR CONN STRING" 
                connectionUsername="<domainName>\administrator" 
                connectionPassword="password"/>
   </providers>
 </membership>
 ...
</system.web>

And you need to setup the conn sting of course

<connectionStrings>
  <add name="YOUR CONN STRING" 
   connectionString=
    "[ANY ConnectionSTRIN]" />
</connectionStrings>
like image 31
brian chandley Avatar answered Sep 25 '22 20:09

brian chandley