My LocalDB connection string isn't letting me access my mdf file
My build is failing here on an integration test that uses LocalDB: https://ci.appveyor.com/project/cottsak/controllertests/build/0.1.2...
My connection string is Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|store.mdf;Integrated
Security=True;Connect Timeout=30
and I get a message like
this from the log:
-------- System.Data.SqlClient.SqlException : Database 'C:\PROJECTS\CONTROLLERTESTS\CONTROLLERTESTS.TESTS\BIN\DEBUG\STORE.MDF' cannot be upgraded because it is read-only, has read-only files or the user does not have permissions to modify some of the files. Make the database or files writeable, and rerun recovery.
An attempt to attach an auto-named database for file C:\projects\controllertests\ControllerTests.Tests\bin\Debug\store.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
I'm not sure what this means but my research suggests that maybe LocalDB won't run in the elevated level that the build script is using (Admin). Can you guys help me out?
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Feodor Fitsner on 05 Feb, 2015 08:20 PM
There are three different SQL Server engines on build worker: http://www.appveyor.com/docs/services-databases
Why wouldn't you just try to attach that MDF to one of them without using LocalBD?
2 Posted by cottsak on 09 Feb, 2015 09:38 AM
@Feodor 1) Because that would be harder
2) Because then I'd have to do something special just to get the build working on AppVeyor
3) Because I really want to use LocalDB since most devs who have a recent version of Sql Server will have LocalDB by default
Support Staff 3 Posted by Feodor Fitsner on 09 Feb, 2015 10:11 PM
OK, then we should investigate further to understand what's wrong with LocalDB on AppVeyor environment! :)
I played with icacls a little bit, but it didn't help. Do you have any other ideas?
4 Posted by cottsak on 10 Feb, 2015 01:25 AM
Can you RDP into a build environment and try loading the solution in there manually and see if the test runner can wind up the tests using LocalDB? That might prove whether it's really a permissions thing or not.
Support Staff 5 Posted by Feodor Fitsner on 10 Feb, 2015 04:37 AM
Yeah, will take a look.
6 Posted by cottsak on 12 Feb, 2015 03:00 PM
Hey @Feodor,
I'm not trying your suggestion of just plain attaching the db files to the instance on the build box. I can't get it work tho. I've enabled
SQL Server 2014 Express
in the Environment settings and this is my script:For the last line I get this error https://ci.appveyor.com/project/cottsak/controllertests/build/0.1.9...
This all worked locally so I know the script is ok. Any ideas what I'm doing wrong?
7 Posted by cottsak on 12 Feb, 2015 03:00 PM
I meant to say "I'm now trying your suggestion.."
Support Staff 8 Posted by Feodor Fitsner on 12 Feb, 2015 03:13 PM
Could it be that SQL Server instance is running under NETWORK SERVICE that doesn't have access to that
.mdf
file?9 Posted by cottsak on 13 Feb, 2015 12:05 AM
Possibly. Do you have any suggestions?
10 Posted by cottsak on 13 Feb, 2015 01:08 AM
Got it working with this:
I suspect there's a compatibility problem with the 2014 instance.
cottsak closed this discussion on 13 Feb, 2015 01:11 AM.
Feodor Fitsner re-opened this discussion on 13 Feb, 2015 01:39 AM
Support Staff 11 Posted by Feodor Fitsner on 13 Feb, 2015 01:39 AM
Thanks for posting the solution here! I think it's worth adding to AppVeyor docs.
So, what version of SQL Server engine was used to create that .mdf?
12 Posted by cottsak on 28 May, 2015 09:25 AM
The file is here https://github.com/cottsak/ControllerTests/blob/master/ControllerTe...
Can you pull the version from it?
Support Staff 13 Posted by Feodor Fitsner on 28 May, 2015 05:42 PM
Could you please elaborate what you mean?
14 Posted by Juan Manuel on 07 Jun, 2018 09:57 PM
The problem is only File .mdf and .log permissions over the user or application ejecution. only give the security permission read and write in the properties file and the connection string for example "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\WinApps17\Cash\Invoices\Data\VFindx.mdf;Integrated Security=True;Connect Timeout=30"
Owen McDonnell closed this discussion on 27 Jun, 2019 05:18 AM.