Solved

ASP.NET connection string problem

Posted on 2015-01-27
9
116 Views
Last Modified: 2015-02-04
Using Visual Studio 2013, I created a local database to handle memberships and roles.  When I try to login on the desktop version, everything works fine.  When I tried to login on the server version of the website, I got an error message.  Another expert said I need to get rid of the LocalDB connection string, and replace it with something like this:

    <add name="DefaultConnection" connectionString="Server=72.18.135.38,1533;Database=aspnet-WillowLane1-f59c4ece-32dd-40f4-9451-1620648a0486.mdf;Uid=xxxxxx;Password=xxxxxx;"
      providerName="System.Data.SqlClient" />

I don't get the error anymore, but my logins always fail.  When I created the database, I was never asked for a username and password.  What should I be using?
0
Comment
Question by:rrhandle8
  • 5
  • 4
9 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 40572423
Few initial questions.

1) What was the error you were originally getting before you changed the connection string?
2) How are you creating/deploying your database? i.e. are you using a code-first, or model first deployment?
3) Where you using LocalDB on your machine to develop against?
4) What version of SQL is on your server where you are deploying to?
0
 

Author Comment

by:rrhandle8
ID: 40573523
I honestly forgot the previous error.  
Yes I was using LocalDB on my machine.
Database on server is MSSQL 2005.
I was using Code-First.
I have received some feedback from support.  The sent me this connectionstring:

 <add name="DefaultConnection" connectionString="Server=.\SQLExpress;AttachDbFilename=C:\HostingSpaces\inomaxne\willowlanecare.inomax.net\wwwroot\App_Data\[database name goes here};Trusted_Connection=Yes;" providerName="System.Data.SqlClient" />

Now I am getting the error:

CREATE DATABASE permission denied in database 'master'.

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.Data.SqlClient.SqlException: CREATE DATABASE permission denied in database 'master'.

Source Error:


Line 22:             ' Validate the user password
Line 23:             Dim manager = New UserManager()
Line 24:             Dim user As ApplicationUser = manager.Find(UserName.Text, Password.Text)
Line 25:             If user IsNot Nothing Then
Line 26:                 IdentityHelper.SignIn(manager, user, RememberMe.Checked)


If you want to see the stack, go to http://willowlanecare.inomax.net, Try to login.
0
 

Author Comment

by:rrhandle8
ID: 40573626
A good article from Microsoft on connection strings to be used in this case.  I have tried all the combination, still nothing works.

https://msdn.microsoft.com/en-us/library/jj653752%28v=vs.110%29.aspx#datasource
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 52

Expert Comment

by:Carl Tawn
ID: 40573649
That error means that the account you are connecting to the SQL Server with (probably the local system account, but basically whatever account IIS is running under) doesn't have CREATE DATABASE permissions on the server.

Personally I'm not a huge fan of an IIS service account having permissions to create databases. But that is what your issue is. So, with that in mind, you either need a named user account in SQL Server that does have CREATE DATABASE permissions, and then use that in your connection string, or you need to give CREATE DATABASE permissions to the IIS service account.
0
 

Author Comment

by:rrhandle8
ID: 40573674
That is the result of one combination of many connection strings I have been experimenting with. Notice in the msdn article above there is no mention of needing those permission.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 40573698
You won't need those permission when using LocalDB, but you will need them if you're trying to attach a database to a full blown SQL Server. You'll also need to make sure the account has read/write access to the directory where the database files are located.
0
 

Author Comment

by:rrhandle8
ID: 40581759
Carl,
Is it OK to use the LocalDB on the production server for a simple little site that will have 10 to 20 visitors a day?  Someone sent me this link https://stackoverflow.com/questions/13571331/is-it-normal-to-use-localdb-in-production
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 40585818
According to that post, and the two articles it points at, it is.  Although you need to jump through a couple of loops to get it to work.

Personally I wouldn't, I would use SQL Express as a minimum. I've never really used SQL Express in a production environment either - that's not to say you can't, or shouldn't, but most environments i've worked in there has been a full-blown SQL install available.
0
 

Author Closing Comment

by:rrhandle8
ID: 40590020
Enough!  I got a separate domain name and a shared hosting account with SQL Server Web.  It works now.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question