April 24, 2013 at 2:30 pm
I am trying to connect to SQL Server 2008 R2 Express from Visual Studio 2012. When executing the VS code it returns the following error:
[SqlException (0x80131904): Directory lookup for the file "c:\users\austens samsung\documents\visual studio 2012\Projects\learning1\learning1\App_Data\test.mdf" failed with the operating system error 5(Access is denied.).
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.]
Do I need to be running VS as administrator? My server is up and running and connected?
The code is trying to create the database test.
Any help would be appreciated.
April 24, 2013 at 2:34 pm
This error usually happens when the account the SQL Server is running under does not have permission to the drive/directory/file being mentioned. Check the account's permissions and make sure the path is relative to the server, not your client.
April 24, 2013 at 2:36 pm
Not sure how to go about doing that. Can someone walk me thru it? Thanks
April 24, 2013 at 3:00 pm
easiest fix is to move it out of your personal folders:
c:\users\austens samsung
a fresh installation of SQL has permissions to it's own folders under program files, and it's own folders under program files(x86), but typically does NOT have permissions to specific users folders.
my 2008 isntallation, for example, typically puts files here by default:
C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA
Lowell
April 24, 2013 at 3:11 pm
Im going to post my connection string from my VS project. Can you tell me what the path should look like?
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="AUSTENSSAMSUNG\SQLEXPRESS;Initial Catalog=aspnet-learning1-20130420131735;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-learning1-20130420131735.mdf" />
<add name="test"
connectionString="Data Source=AUSTENSSAMSUNG\SQLEXPRESS;AttachDbFilename=|DataDirectory|\wingtiptoys.mdf;Integrated Security=True"
providerName="System.Data.SqlClient " />
</connectionStrings>
April 24, 2013 at 5:06 pm
So let me understand. Where do I install my SQL Server during the installation? Or is it a problem with the VS project? Confused.
April 25, 2013 at 5:14 am
austen.robinson (4/24/2013)
So let me understand. Where do I install my SQL Server during the installation? Or is it a problem with the VS project? Confused.
Ok your problem is purely permissions to a specific folder.
The SQL Service typically runs as a user who is not a local admin on the operating system, so cannot read data from any users Desktop/documents:
your fix is simple: if you are going to attach a database via conneciton string, the file cannot be in your personal folders.
Create a c:\SQLData folder, for exmaple, and put it there, or put it in the folder i mentioned above, since that is where SLq has at least four other databases already.
then change your connection string to match the new folder:
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="AUSTENSSAMSUNG\SQLEXPRESS;Initial Catalog=aspnet-learning1-20130420131735;Integrated Security=SSPI;AttachDBFilename=C:\SQLData\aspnet-learning1-20130420131735.mdf" />
<add name="test"
connectionString="Data Source=AUSTENSSAMSUNG\SQLEXPRESS;AttachDbFilename=|DataDirectory|\wingtiptoys.mdf;Integrated Security=True"
providerName="System.Data.SqlClient " />
</connectionStrings>
the second option is to go to the service, and make it start as yourself...since you are a local admin on your own laptop/machine, the permissions problem would also go away:
you can prove this is the issue by simply putting in your credentials, with your domain account and password, and confirm the external object you were trying to access/use works when SQL is run your credentials, so you'd know you need a domain or local account to access the resource.
note you have to stop and start the service after you change the credentials before it will start using those credentials.
Lowell
April 25, 2013 at 10:00 am
I like the first option you gave. What is the entire path in the "This User" above in the example you provided?
April 25, 2013 at 6:29 pm
Ok, here is my current connection string. I now throws the error:
Invalid value for key attachdbfilename
Connection string: (this is where the rest of my databases are located)
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA;Initial Catalog=aspnet-learning1-20130420131735;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-learning1-20130420131735.mdf" />
<add name="WingtipToys"
connectionString="Data Source=C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA;AttachDbFilename=|DataDirectory|\wingtiptoys.mdf;Integrated Security=True"
providerName="System.Data.SqlClient " />
Havent moved my VS project yet.
If I created the folder you suggested (c:\SQLData) and put my project there will it clear the attachdbfilename error?
April 25, 2013 at 7:48 pm
I'm going to post my Visual Studio project and if anyone can get the connection string to work and tell me how they did it I would appreciate it.
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply