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.

Recommended Answers

All 4 Replies

well lets start with this

what is the connection string?

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.

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.