emilio

emilio

  • NA
  • 8
  • 0

exception in executing a stored procedure

Mar 6 2009 5:17 AM
hi
I'm trying to execute a stored procedure which returns a datatable
my code is:

  1. try {

  2. string conStr = WebConfigurationManager.ConnectionStrings[0].ConnectionString;
  3. SqlDataAdapter adapter;
  4. DataTable ans = new DataTable();
  5. SqlConnection connection = new SqlConnection(conStr);
  6. SqlCommand command = new SqlCommand();
  7. command.CommandType = CommandType.StoredProcedure;
  8. command.CommandText = "usp_GetUserDetails";
  9.  
  10. command.Parameters.Add("@UserName", SqlDbType.VarChar);
  11. command.Parameters.Add("@Password", SqlDbType.VarChar);
  12. command.Parameters["@UserName"].Value = user;
  13. command.Parameters["@UserName"].Direction = ParameterDirection.Input;
  14. command.Parameters["@Password"].Value = pass;
  15. command.Parameters["@Password"].Direction = ParameterDirection.Input;
  16.  
  17. adapter = new SqlDataAdapter(command.CommandText, connection);
  18. adapter.Fill(ans);
  19.  
  20. return ans;
  21. }
  22. catch (Exception ex)
  23. {
  24. throw ex;
  25. }

when i execute i get an exception:
An attempt to attach an auto-named database for file C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\WebSites\WebSite1\App_Data\aspnetdb.mdf failed. A database with the same name exists, or specified file cannot be Opened, or it is located on UNC share.

the connection string is:

  1. <add name="MainConnectionString" connectionString="Data Source=MIKLAT\SQLEXPRESS;Initial Catalog=...;Integrated Security=True; providerName="System.Data.SqlClient"/>

I'm not running this site from iis, just from visual studio 2008.
the database is located in c:\program files\sql 2005 ....

i tried to look for a solution but didnt find something helpfull.

Answers (1)