using login controls with sql server (not express)

976 Views Asked by At

I installed Visual Studio 2008 Professional(updated with SP1), then I uninstalled SQL server 2005 Express and installed SQL Server 2005 Standard.

now I am not able to add 'SQL Server Database' to the project - it says Connections to SQL Server files (*.mdf) require SQL Server Express 2005 to function properly.

Is it not compliant with SQL Server Standard version?

And Login Controls also not working-
Web Administration Tool says Unable to connect to SQL Server database

Also tried with aspnet_regsql command-line utility.. not working..(actually I dont know what is to be done after creating SQL server database through 'aspnet_regsql command-line utility')

Please Provide a solution for my problem before somebody Closes this question or marks for deletion ;P :)

1

There are 1 best solutions below

4
On BEST ANSWER

The functionality to just attach a stand-alone .mdf file as a database is indeed available in the Express editions of SQL Server only.

What you should do in any other case is create the database on the SQL Server instance, and refer to it by its database name - not it's .mdf file name.

In order to create those tables and stored procedures needed for the ASP.NET membership and role subsystem, you need to use the aspnet_regsql utility against your SQL Server instance. You said that didn't work - how does it not work?? Did you get an error ?? If so: what error??

See the MSDN docs on aspnet_regsql for details on how to use it. To create the ASP.NET membership and role subsystem, use:

aspnet_regsql -S (your server name here) -E -A mr

The -E uses integrated security (e.g. your current Windows logon) to connect to SQL Server - that user accounts needs enough permissions for these operations, of course! If you need a specific SQL Server user, there's are the two -U (username) -P (password) parameters to achieve this.

Once you have all of this, you also need to configure your ASP.NET membership and role subsystem to actually use that new database (ASPNETDB) that was created on your SQL Server. By default, they use the aspnetdb.mdf file attached to your SQL Server Express instance. Since you've changed that, you need to update your configuration! See how to do this in detail on MSDN

Step 1: add a connection string to your newly created database

In your web.config or app.config, add a valid connection string to your newly created ASP.NET membership/role database - something like:

<configuration>
   <connectionStrings>
      <add name="ASPNETDB_Connection" 
           connectionString="Server=YourServer;database=aspnetdb;Integrated Security=SSPI;" />
  </connectionStrings>

Step 2: - add a valid configuration for the ASP.NET membership subsystem and reference that new connection string you've just added in Step 1; something like:

<configuration>
   <system.web>
      <membership defaultProvider="YourProvider" userIsOnlineTimeWindow="15">
          <providers>
             <clear />
             <add name="YourProvider" 
                  type="System.Web.Security.SqlMembershipProvider" 
                  connectionStringName="ASPNETDB_Connection"
                  applicationName="MyApplication"
                  enablePasswordRetrieval="false" enablePasswordReset="true"
                  requiresQuestionAndAnswer="true" requiresUniqueEmail="true"
                  passwordFormat="Hashed" />
          </providers>
      </membership>

Step 3: do the same for the role subsystem:

<configuration>
   <system.web>
      <roleManager defaultProvider="YourProvider" enabled="true" cacheRolesInCookie="true" >
          <providers>
             <clear />
             <add name="YourProvider" 
                  type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"                 
                  connectionStringName="ASPNETDB_Connection"
                  applicationName="MyApplication" />
          </providers>
      </roleManager>