Solved

ASP.NET connection string problem

Posted on 2015-01-27
9
114 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now