Misto
Misto

Reputation: 21

How to make portable exe program (C#) use a database (SQL Server Express) on a local network

I'm designing a portable c# program with a SQL Server Express database (.mdf file) which will be used by multiple computers. And I'm trying to make every user work on the same database allocated on a certain computer on the local network.

My problem is when a convert my C# program portable exe, I can't make my program to use the specified database on network. It only sees the database I attached on the folder which contains my portable exe program.

connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Gorev.mdf;Integrated Security=True;User Instance=True" 

This is my connection string. Did I make a mistake?

I use Visual C# 2010 Express edition as compiler.

Please help me to overcome this problem. Thanks in advance

Upvotes: 2

Views: 1229

Answers (1)

ebadola sobhanwerdy
ebadola sobhanwerdy

Reputation: 31

I think you connection string is wrong You should first Attach your database on server Computer that hosted your SQLServer
Then on connection string changeData Source=.\SQLEXPRESStoData Source=ComputerName\SQLEXPRESS and then Instated offAttachDbFilename=|DataDirectory|\Gorev.mdfyou should Set Database name like thisInitial catalog=Gorev
finally you connection string should be like follow line

connectionString="Data Source=ComputerName\SQLEXPRESS;Initial catalog=Gorev;Integrated Security=True;User Instance=True"


ComputerName should be name of computers is hosted SQLServer
SQLEXPRESS is Instance of SQLServer and this name is Default and you should replace with you sqlserver instance

Pleas Visit http://blogs.msdn.com/b/sqlexpress/archive/2005/05/05/415084.aspx How to enable SqlSever for remote connection
Pleas Visit https://www.connectionstrings.com/sql-server/ sql server Connection string Pattern

Upvotes: 3

Related Questions