I have developed an application that have a slider that showing some data from a SQL Database. I'm using Visual Studio 2010 and Microsoft SQL Server 2008.
In fact i don't face any problem with my application when i deploy it an run it on my Personal Computer. The problem occurs when i try it on another machine, and the problem is that the application couldn't be connected the SQL database. I tried to figure out the reason of the problem, so i tried it after its deployment on two machines, one of them have a SQL server installed on it, and the other one don't have the SQL Server. The Application worked perfectly on the machine that have the SQL Server installed on it, and it couldn't be connected to the database on the other machine.
This is the Connection String i have used in my application>>
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\KBank.mdf;Integrated Security=True;User Instance=True"
so if there is a way that could enable me to run the application without needing the machine to have a SQL Server installed, i would be grateful. Thanks
Your connection string is using localhost which is represented via the
.
in the connection string. This won't work if the machine does not have SQL Server Installed, therefore you need to change the connection string to the remote machine (The machine with a SQL Server Installation, i.e. Your personal computer).You need to change the connection string to specify the computer the database is installed on. Something like the following:
Please note: The database on the other machine needs to be configured properly so it can be accessed from other machines.
If you do not want to have a SQL Server Express installed, you can go for an embedded SQL server via sql server compact(http://en.wikipedia.org/wiki/SQL_Server_Compact) or alternatively have an actual networked database available.
If you using centerl database install in Server computer and other all client computer can access to that sever.
If it's you can doing the following way:
first you change your program to write File DSN to Hard disk at start up of program
Use the following code as sample
Enter your server Ip as
string server
Now you can use connection in separate class
Now you can write following code your different required place for connect to database,
If you need SELECT query:
If you need Insert, Update, Delete query
This method can use connect to database without any configurations.
Important: keep remember delete DSN file when exit application for security purpose.
Hope this will help you!
You need to do one of the following:
There are other data access strategies you could employ, such as serializing the data as XML, or using a different database like SQLite or using web services, but put simply, if SQL Server Express isn't installed on your client's machine, you can't force it to work.