0

hi
I'm trying to execute a stored procedure which returns a datatable
my code is:

try
            {
                string conStr = WebConfigurationManager.ConnectionStrings[0].ConnectionString;
                SqlDataAdapter adapter;
                DataTable ans = new DataTable();
                SqlConnection connection = new SqlConnection(conStr);
                SqlCommand command = new SqlCommand();
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "usp_GetUserDetails";

                command.Parameters.Add("@UserName", SqlDbType.VarChar);
                command.Parameters.Add("@Password", SqlDbType.VarChar);
                command.Parameters["@UserName"].Value = user;
                command.Parameters["@UserName"].Direction = ParameterDirection.Input;
                command.Parameters["@Password"].Value = pass;
                command.Parameters["@Password"].Direction = ParameterDirection.Input;

                adapter = new SqlDataAdapter(command.CommandText, connection);
                adapter.Fill(ans);

                return ans; 
            }
            catch (Exception ex)
            {
                throw ex;
            }

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.

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

3
Contributors
4
Replies
6
Views
8 Years
Discussion Span
Last Post by emilio
0

More than likely the IIS service cannot access that file since it should be run under an unprivelaged account, and the database you're referencing in buried in your userspace documents.

Try to move the file to a common location for testing.

0

the connection string is:

<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 .....

0

my mistake, i used the wrong connection string.
thanks for the help

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.