Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

How to solve this error? -"A database with the same name exists, or specified file cannot be opened"?


  • Please log in to reply
2 replies to this topic

#1 reyad009

reyad009

  • Members
  • 1 posts
  • OFFLINE
  •  
  • Local time:01:58 PM

Posted 12 August 2011 - 11:28 AM

Whenever i try to login( (after debugging ) it shows me this error message.
http://img846.imageshack.us/img846/2403/
May be i've some issue with connectionstring.
Here is my dataaccess code:.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace registation
{
class DataAccess
{

static string _ConnectionString = registation.Properties.Settings.Default.…

static SqlConnection _Connection = null;
public static SqlConnection Connection
{
get
{
if (_Connection == null)
{
_Connection = new SqlConnection(_ConnectionString);
_Connection.Open();

return _Connection;
}
else if (_Connection.State != System.Data.ConnectionState.Open)
{
_Connection.Open();

return _Connection;
}
else
{
return _Connection;
}
}
}

public static DataSet GetDataSet(string sql)
{
SqlCommand cmd = new SqlCommand(sql, Connection);
SqlDataAdapter adp = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
adp.Fill(ds);
Connection.Close();

return ds;
}

public static DataTable GetDataTable(string sql)
{
DataSet ds = GetDataSet(sql);

if (ds.Tables.Count > 0)
return ds.Tables[0];
return null;
}

public static int ExecuteSQL(string sql)
{
SqlCommand cmd = new SqlCommand(sql, Connection);
return cmd.ExecuteNonQuery();
}

}
}

Please help me out. I'm using Microsoft visual C# 2008 Express Edition. Give as much information as u can.

Edited by groovicus, 12 August 2011 - 02:55 PM.


BC AdBot (Login to Remove)

 


#2 cryptodan

cryptodan

    Bleepin Madman


  • Members
  • 21,868 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Catonsville, Md
  • Local time:07:58 AM

Posted 12 August 2011 - 11:29 AM

First thing I see is no SQL Statements stating what database to use and what to query.

#3 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:01:58 AM

Posted 12 August 2011 - 02:56 PM

Your image has been removed, so we cannot tell you what the problem is. Based on the title of the thread, you are trying to create a database with the same name as one that already exists. In general, if you cannot connect to the database, you are going to get an error that indicates just that.

And for pity's sake, format your code. :(

Edited by groovicus, 12 August 2011 - 02:58 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users