hi... i m getting error like this in my code
public partial class items : Form
{
string con = "Server=.\\SQLEXPRESS;Database=|DataDirectory|/db1.mdf;Trusted_Connection=True;";
SqlDataAdapter da = new SqlDataAdapter();
SqlConnection objconnection;
private void btnshow_Click(object sender, EventArgs e)
{
objconnection = new SqlConnection(con);
objconnection.Open(); <-------ERROR
string ss=comboBox1.SelectedValue.ToString();
string q = "select * from items where cname= " + "'" + ss.ToString() + "'";
SqlCommand comm = new SqlCommand("select * from items where cname=@cname", objconnection);
comm.Parameters.AddWithValue("@cname", ss.ToString());
comm.ExecuteNonQuery();
textBox1.Text = comboBox1.SelectedValue.ToString();
da = new SqlDataAdapter(q, con);
DataSet ds = new DataSet();
da.Fill(ds);
dataGrid1.DataSource = ds.Tables[0];
}
Error
Cannot open database "|DataDirectory|/db1.mdf" requested by the login. The login failed.
Login failed for user 'AHUJA-2FD08D31D\Ahuja's'.
Loading

JosePosted Jan 27, 2010, 10:24 AM
Try editing your connection string to something like:
Jose
Dipa AhujaPosted Jan 23, 2010, 7:44 AM
bt i dont know how to write in c# :(
JosePosted Jan 22, 2010, 11:58 AM
You can also test your connectivity to the database by going to the Data sources (ODBC) snapin from the Control Panel > Administrative tools. From there, you can click on the system DSN tab, and add new. Select SQL Server at the bottom of the list, then click Finish. On the next screen give it a name (any name will do) and make sure the local server ".\SQLEXPRESS" is shown in the last field, then click Next. Now you get to the authentication part. Make sure the first option is selected (NT authentication), and check the box below and click Next. At this point, if you are authenticated to the SQL server instance, you should see a combo box with the list of databases (after checking Change default database to). If you get this far, select the database you are trying to connect to and click next and then finish. On the final screen, click the Test button to see if the connection is successful. If not, try making the tweaks from the SQLExpress instance. Might need to add the user role to that database if it does not have access.
Dipa AhujaPosted Jan 22, 2010, 11:53 AM
n i m not getting help anywhere... :(
Lalit MPosted Jan 22, 2010, 1:16 AM
http://blogs.msdn.com/sql_protocols/archive/2006/02/21/536201.aspx
Santhosh NPosted Jan 22, 2010, 12:53 AM
try to login to the instance first with userrname and password and provide the same in the connection string and check