I am trying to figure out a way to use a LocalDB in place of SQL for integration testing of EF6 queries (this would allow us to run integration tests on our build server). It seems like I should be able to replicate my database in SQL Express, detach, and import into my test project.
I would expect from there I can modify my connection string in my test project to hit the local database file. I am running into a security issue though. I need to get SQL security working to pass in a user id and password in my conn string (since the build server will not be using my domain account), but regardless of what I try I get a bad username or password error as soon as I try to query. My connection string looks like this:
<add name="ClinicalContext" connectionString="metadata=res://*/ClinicalDataStore.csdl|res://*/ClinicalDataStore.ssdl|res://*/ClinicalDataStore.msl;provider=System.Data.SqlClient;provider connection string="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\ClinicalDataStore.mdf;Integrated Security=False;User Id=SomeUser;Password=SomeUsersPassword;""
providerName="System.Data.EntityClient" />
Does anyone have any experience with this and know if I need to do something particular to get sql security to work this way?
Update
I attached the database file via Server Explorer and checked the updated connection string. The only change was to add an Initial Catalog and change the security back to integrated. If I try to connect that way, I get an error that it cannot access the catalog as the defined name. If I change back to sql security I still get the bad username or password error.
Related
I'm getting this error please help me :(
The context is being used in Code First mode with code that was generated from an EDMX file for either Database First or Model First development. This will not work correctly. To fix this problem do not remove the line of code that throws this exception. If you wish to use Database First or Model First, then make sure that the Entity Framework connection string is included in the app.config or web.config of the start-up project. If you are creating your own DbConnection, then make sure that it is an EntityConnection and not some other type of DbConnection, and that you pass it to one of the base DbContext constructors that take a DbConnection. To learn more about Code First, Database First, and Model First see the Entity Framework documentation here: http://go.microsoft.com/fwlink/?LinkId=394715
Here's my connection string:
connectionString="metadata=res://*/dbEspesyalTea.csdl|res://*/dbEspesyalTea.ssdl|res://*/dbEspesyalTea.msl;provider=System.Data.SqlClient;provider connection string="data source=tcp:[hidden].database.windows.net,1433;initial catalog=dbET;persist security info=True;user id=[hidden];password= [hidden];MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient"
This is an application configuration problem.
The exception is telling you that that
connectionString="metadata=res://*/dbEspesyalTea.csdl|res://*/dbEspesyalTea.ssdl|res://*/dbEspesyalTea.msl;
is not your connection string. And somehow you've configured the deployed application to use a plain SQL Server connection string and not an "entity connection string" (ie with the edmx file locations).
So double-check and then log the connection string your deployed application is using.
I'm using Umbraco CMS v7.4 with SQL Server 2014, the project was working fine until a few hours ago, when an error started showing up:
Umbraco cannot start. A connection string is configured but the Umbraco cannot connect to the database
The error occurs when I tried to open the website, see the image below:
I tried the following:
Checked to see if SQL Server is running
Checked the connection string credentials in web.config
Any help is appreciated.
After a few tries, even I loaded the backed up DB, I found that it caused by the DB login, the user in the connection string was having a password expiration enabled (the password had expired).
So, this is what I did:
Open the SQL server
Logged in as the user used in the connection string
Created a new password
Updated the web.config connection string "Password"
Hope this will help
So, in my case I tried to get started with the existing project. I got all the files, restored DB backup locally, made sure all permissions are set for IIS AppPool user etc. But I kept getting the error in question. It turns out that I cannot use server=localhost;database=... in connection string. After I replaced it with server=.\;database=..., it started to work right away.
Also note that if you're running it in Azure with an Azure SQL database you'll have to go to the Azure SQL Server settings and under "Firewalls and virtual networks" you'll need to tick "Yes" for "Allow Azure services and resources to access this server".
I was getting this error when running an Umbraco project locally, with the DB pointing to an instance on Azure. In that case, this problem happens if you haven't allowed the IP access within the Server Firewall of the DB in Azure.
You can fix this by finding out your IP and then adding it to the DB:
Click All Resources within your Azure portal, then click on the SQL Database your project points to.
Click Set Server Firewall on the right-side window.
Add in your IP as the start and end points, and call it something memorable.
Click Save and once you get the confirmation message that It has been applied, refresh your site locally.
I experienced the same problem and here is how I fixed it.
Right-click on your localhost in SSMS and select Properties
Got to the Security page and select "Select authentication" as "SQL Server and Windows Authentication mode"
Hit OK.
Go to Services and find your SQL Server service and restart it.
Check your local umbraco website now, you should be able to see it without any issues. If you still have problems, then you might need to check your local setup and permissions.
Further details are below and on this blog post.
I'm trying to install Umbraco on an ASP.NET environment. After I downloaded the umbraco nuget package I tried to run the installation wizard, by building and running the project. All is fine and good, if i take the default database configuration, but if I want to customize my configuration, it fails and says :
"Could not connect to database"
I'm trying to configure it to use my local SQLExpress database, but I just cannot get it working. I have both tried putting in the server information and connecting via. a connection string, via. the wizard. It produces the same error every time.
I have made a database called umbracoblog and created an admin user, with credentials. He has dbowner etc. for the database. Besides that, I have also given full permissions to IIS_IUSRS and Network Service accounts for the project and all subdirectories, and it still doesn't work.
These are some of the connection strings I have tried:
datalayer=SqlServer;Data Source=.\SQLExpress;Initial Catalog=umbracoblog;User Id=admin;Password=********;
datalayer=SqlServer;Data Source=127.0.0.1\SQLExpress;Initial Catalog=umbracoblog;User Id=admin;Password=*******;
I have also tried putting in the connectionstring into the web.config, manually, but that just makes the project load infinitely in the browser, when I run it.
It's starting to get frustrating, that I cannot even get past the configuration of Umbraco, because it look very cool. I have tried everything I was able to found online. Have anyone gone through this and know what I need to do ?
Start again - clear out and remove the umbracoDbDSN connection string entirely from your web.config and reset the umbracoConfigurationStatus AppSetting back to empty if it has been populated.
Use the Wizard to configure the database - if it's still having problems connecting then here's a few things to check:
Check the Log file here: ~/App_Settings/Logs/UmbracoTraceLog.txt - does that show up any errors?
Make sure you can connect to the database using other clients - if Umbraco can't connect to it, chances are something else won't be able to as well.
What happens if you use Integrated Authentication? If that works, then it's most likely an issue with the username and password you specified.
The password I had for the SQL Server user had a character that the installation UI didn't accept. I changed the password to remove special characters and it was able to connect to the server again. I could successfully log in through SSMS with the previous password.
I've recently been placed on a project using EF 6.0 and Code First principles. The ApplicationDbContext is loaded from this connection string:
name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Integrated Security=True" providerName="System.Data.SqlClient"
As you can see there is no specified Initial Catalog, and yet the data is being stored SOMEWHERE? I have searched the LocalDb instance through the file system, MS VS 2013 and SQL Server Management studio.
The problem is the current devs have created a substantial amount of dummy data we don't want to lose. Does anyone know where this data is being stored and/or how it can be retrieved?
Many thanks.
When a user opens a connection without specifying the DB (aka catalog), it gets a connection to his default DB.
If you have not changed the configuration it will most probably be the master DB.
You can confimr this using SSMS. Connect to your server, go to Security > Logins, choose the login used to connect to the DB (as you're using Integrated security it must be the user which starts the app, or the application pool user if it's a web app), right click, choose "Properties", and, in the General panel, at the bottom, you'll see what the default DB is.
NOTE: perhaps I'm not using the exact wording, as I have a localized SSMS, and I am supposing what the translation is.
I use the following connection string when working on my dev machine:
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
This works every time.
However, when I go to deploy to a remote IIS server that is a dedicated host (SQLEXPRESS should work just fine without the worries associated with a shared server), the same connection string results in a failure to connect to the database.
The database files are stored in App_Data within the directory of the application on the development environment and on the deployment environment. I just can't seem to connect to the database on the deployment environment (although the file is sitting there).
Do I need to have my host somehow give me a username / password so I can add it to the connection string? Or do I need to change my connection string in some other way?
I've never used SQLExpress (well not in anger) but remember that once you're on IIS you're running under a different account than when you're debugging. This would be the account under which the IIS app pool is configured to run. So, when you say you want to use integrated security to access this database, you need to configure it to recognize that particular account (whichever it is, for example NETWORK_SERVICE).
In a hosting environment you're probably better off just using SQL authentication, although that's obviously less secure since you have to store the password somewhere. And you'd still have to change the DB security settings.
Otherwise, if you do know the account under which the app pool is running then it's just a matter of configuring the DB to accept connections from it.