I'm trying to execute a stored procedure which returns a datatable
my code is:
Java
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.
the connection string is:
Code
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

the database is located in c:\program files\sql 2005 ....
i tried to look for a solution but didnt find something helpfull.

Sateesh ArvetiRank #96 · 22.3K reputationPosted Mar 6, 2009, 1:52 AM EST
Addin thesection of the web.config and make sure connectionstring is correct.