0

I have created a new ASP.Net project in C#. I have added a new database inside my App_Data folder called aspnetdb.mdf. I have added the following connection string to my project:

<add name="ApplicationServices" 
    connectionString="data source=.\SQLEXPRESS;
    Integrated Security=SSPI;
    AttachDBFilename=|DataDirectory|\aspnetdb.mdf;
    User Instance=true" providerName="System.Data.SqlClient" />

When I run my project, it retrieves the data just fine.

Now I want to write some new stored procedures. So I open the query window to do so:

enter image description here

When I try to run a simple SELECT statement, I get an error:

enter image description here

Can anyone tell me how I can return data from this table? Keep in mind this is being done inside VS2010 and not in SQL Server as I don't have the full-blown SQL Server installed on my computer (although VS2010 installed some pieces of SQL Server 2008).

Johnny Bones
  • 8,786
  • 7
  • 52
  • 117
  • Check this Post http://stackoverflow.com/questions/4234244/how-to-run-an-sql-script-against-a-mdf-file – Shetty Oct 13 '15 at 11:08
  • please ensure that your query editor is using the correct database. first run the use[your_database_name] query then execute select query – Sain Pradeep Oct 13 '15 at 11:29
  • @Shetty - That worked at first, now I'm getting an error: Cannot open database "LocalData" requested by the login. The login failed. – Johnny Bones Oct 13 '15 at 13:01
  • When you clicked on connect, What username passwrod did u use? Did you use Windows Authentication? – Shetty Oct 13 '15 at 14:17
  • Looks like the login which you have does not have permission to access the new db you have created (With logical name LocalData). This can help https://msdn.microsoft.com/en-us/library/ms239722.aspx – Shetty Oct 13 '15 at 14:38
  • Turns out the database name becomes persistent, and so every time I run that fix from Shetty's link, I have to change the database name. Weird. Eventually I'm gonna run out of names... – Johnny Bones Oct 13 '15 at 16:55
  • Isnt it possible for you to have SQL server express edition installed on your local machine and attached the mdf file? – Shetty Oct 14 '15 at 07:20

0 Answers0