In c#, I decided to substitute local SQL database for my previous programs used Access or Excel DB services before.
I want to use this database locally and I do not decide on using it in web.
But there are some problems.
I made a program and add a local database through:
Solution Explorer> right click on name of project> Add > New Item
then select "Local Database" and add a database with name: Database1.sdf
Then I added a tabel with two fields.
Also This class was added to my program automaticly: Database1DataSet
In my code I wrote:
Database1DataSet ds = new Database1DataSet();
const string TableName = "Users";
private void InitalizeDatabase()
newMode = false;
string strSql = "SELECT * FROM " + TableName;
cn = new SqlConnection("Data Source=(local);Initial
Catalog=Database1;Integrated Security=True;Connection Timeout=10");
da = new SqlDataAdapter(strSql, cn);
new Binding("Text", ds, TableName + ".UserName"));
new Binding("Text", ds, TableName + ".Password"));
new Binding("DataSource", ds, TableName));
There was no error in compiling, but a runtime error appears each time I run the program at the line:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
I tried many string connections, and always an exception was appeared with one of these codes: 0, 26, 40
It harassed me. I have not installed SQL but SQL services are avalable in my Windows7 by default. and I actived all of them manually:
Although some of prograsmmers say no SQL installation is needed but I got doughbtful.
Is there anyone help me how to deal with such a problem?
Thx very much.