Jump to content

C# - Relative Data Source


Recommended Posts

I currently have my data source hard coded, is it possible to have a relative data source so that I can run it on a number of computers? All files are stored in a folder, with my database stored within an App_Data folder.My current code:

//create connection to database    SqlConnection connection = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\greenApple\\Desktop\\new_forum\\App_Data\\members.mdf;Integrated Security=True;User Instance=True");    SqlCommand cmd;    protected void Availability_Click(object sender, EventArgs e)    {        connection.Open();//open connection        cmd = new SqlCommand("SELECT * FROM member WHERE username='" + txtUserName.Text + "'", connection);// sql command to read from members table    }    protected void btnRegister_Click(object sender, EventArgs e)    {        connection.Open();//open connection        cmd = new SqlCommand("INSERT INTO member (username, password) VALUES ('" + txtUserName.Text + "','" + txtPassword.Text + "')", connection);        cmd.ExecuteNonQuery();    }

Any help would be great!!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...