Connecting to a c# Local Database
-
I would like to be able to connect to and read/modify a local database file from the coding side of c#. I am using Visual C# 2008 Express Edition but don't want to use the 'Data Sources' wizard, but rather the 'SqlConnection' Coding commands. I am using Microsoft SQL server 3.5 Database files. Thanks in advance. :-D
you should use Data class of framework. Using data; SqlConnection dataConn = new SqlConnection();, dataConn.ConnectionString = "Integrated Security = True; Initial Catalog =dbName; Data Source=localhost;" dataconn.open(); after this time u ll have a data conn what db you wrote there. Then time you should search what you wanna want.
thanks for everything i have...
-
you should use Data class of framework. Using data; SqlConnection dataConn = new SqlConnection();, dataConn.ConnectionString = "Integrated Security = True; Initial Catalog =dbName; Data Source=localhost;" dataconn.open(); after this time u ll have a data conn what db you wrote there. Then time you should search what you wanna want.
thanks for everything i have...
Sorry, I have tried to connect using this method, the file is called Register.sdf and is in the same directory as the project content. This code fails to load the database effectively. This is the code I am trying to use (The 'Global' Class is a static class containing the RegDB Variable)
private bool loadDatabase() {
Global.RegDB = new SqlConnection();
Global.RegDB.ConnectionString = "Integrated Security = True; Initial Catalog =dbName; Data Source=localhost;";
try {
Global.RegDB.Open();
return true;
}
catch {
return false;
}
} -
you should use Data class of framework. Using data; SqlConnection dataConn = new SqlConnection();, dataConn.ConnectionString = "Integrated Security = True; Initial Catalog =dbName; Data Source=localhost;" dataconn.open(); after this time u ll have a data conn what db you wrote there. Then time you should search what you wanna want.
thanks for everything i have...
TALHAKOSEN wrote:
did you take an error like below TITLE: Connect to Server ------------------------------ Cannot connect to C:\DEV\SyncServices\learning\ConsoleSync1\ConsoleSync1\bin\Debug\awclientdb.sdf. ------------------------------ ADDITIONAL INFORMATION: You are trying to access an older version of a SQL Server Compact Edition database. If this is a SQL Server CE 1.0 or 2.0 database, run upgrade.exe. If this is a SQL Server Compact Edition 3.0 or later database, run Compact / Repair. [ Db version = 3505053,Requested version = 3004180,File name = C:\DEV\SyncServices\learning\ConsoleSync1\ConsoleSync1\bin\Debug\awclientdb.sdf ] (SQL Server Compact Edition ADO.NET Data Provider) ------------------------------ BUTTONS: OK
No, the function just failed in the try block and then returned false in the catch block
-
I would like to be able to connect to and read/modify a local database file from the coding side of c#. I am using Visual C# 2008 Express Edition but don't want to use the 'Data Sources' wizard, but rather the 'SqlConnection' Coding commands. I am using Microsoft SQL server 3.5 Database files. Thanks in advance. :-D
-
http://connectionstrings.com/[^] Is anyone else getting sick of this basic question?!?
Blog link to be reinstated at a later date.
No, I don't think that I have explained myself correctly. I want to be able to access the database file as if it were a database, but without running SQL server. I plan to move the program to another machine that is not running SQL server.
-
No, I don't think that I have explained myself correctly. I want to be able to access the database file as if it were a database, but without running SQL server. I plan to move the program to another machine that is not running SQL server.
You can't use a SQL Server database without SQL Server AFAIK. SQL Server doesn't come built-in to the .NET framework. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
No, I don't think that I have explained myself correctly. I want to be able to access the database file as if it were a database, but without running SQL server. I plan to move the program to another machine that is not running SQL server.
Isn't that like trying to open an MS Excel document without Microsoft Excel? I imagine, if you want, you could open the SDF as a text file and have a look inside, but it won't act as a database without a database server. The clue is in the name - server. It 'serves' the data. The fact that the underlying datastore is a file is irrelevant.
Knowledge is hereditary, it will find its way up or down. Luc Pattyn
and since what every time when i want to add button to this control one add two times posted in C# forum -
I would like to be able to connect to and read/modify a local database file from the coding side of c#. I am using Visual C# 2008 Express Edition but don't want to use the 'Data Sources' wizard, but rather the 'SqlConnection' Coding commands. I am using Microsoft SQL server 3.5 Database files. Thanks in advance. :-D
-
Isn't that like trying to open an MS Excel document without Microsoft Excel? I imagine, if you want, you could open the SDF as a text file and have a look inside, but it won't act as a database without a database server. The clue is in the name - server. It 'serves' the data. The fact that the underlying datastore is a file is irrelevant.
Knowledge is hereditary, it will find its way up or down. Luc Pattyn
and since what every time when i want to add button to this control one add two times posted in C# forumOk, Thanks. I will investigate using SQLite as I have haerd that that can be used without a server (I.E Integrated) Thanks anyway.
-
http://connectionstrings.com/[^] Is anyone else getting sick of this basic question?!?
Blog link to be reinstated at a later date.
My Paranoid Hubby wrote:
anyone else getting sick of this basic question?
Yes, which is why I generally ignore them.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
-
I would like to be able to connect to and read/modify a local database file from the coding side of c#. I am using Visual C# 2008 Express Edition but don't want to use the 'Data Sources' wizard, but rather the 'SqlConnection' Coding commands. I am using Microsoft SQL server 3.5 Database files. Thanks in advance. :-D