Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i have this C# project in visual studio 2015 backend SQL Server 2014.
when i try to run on another PC the connection string wont work.i googled and found
"https://www.connectionstrings.com/sql-server-2014/"
helpful but i dont know what i am doing wrong.

What I have tried:

the connection string which works fine on my machine is :

<pre>   string str = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\xpert\Documents\RFID_DB.mdf;Integrated Security=True;Connect Timeout=30";


i have installed and updated correct version of SQL on Client PC.Please help me with the correct connection string.
Posted
Updated 31-Mar-17 23:33pm

1 solution

Well, no - it won't work!
Firstly, LocalDB is a specific name which means "on this computer" - and unless you have installed SQL Server on both computers (which I don't recommend) the connection string must refer to the specific computer running the instance of SQL server holding the database you need to connect to.
Secondly, you only attach databases for development - you cannot attach a DB in production as "full" SQL server doesn't support it. You should add the DB to SQL properly, and connect to it, never try to attach except when you are developing the software.
Thirdly, Integrated security may well be a problem - unless you have specifically permitted your domain to access the "target" computer, it won't work. And it's a bad idea anyway, you should create users with only the relevant permissions: INSERT row, UPDATE row, DELETE row. Integrated security gives full permissions, which means that they can edit or delete tables in your DB.

We can't tell you exactly what to use: we don't have access to your LAN.
But these are the two strings I use for my local access:
Connection=Data Source=GRIFF-DESKTOP\SQLEXPRESS;Initial Catalog={0};Integrated Security=True

And my tablet:
Connection=Data Source=GRIFF-DESKTOP\SQLEXPRESS;Initial Catalog={0};Persist Security Info=True;User ID=MyUserName;Password=MyUserPassword
Where {0} is replaced with the DB name.
 
Share this answer
 
Comments
Nazneen s 1-Apr-17 7:40am    
when i placed my Database into common restore point it worked fine but now not able to view Reports getting error regarding some entity framework. so can it be due to version problem coz my machine has Win 10 and client machine win 7?
OriginalGriff 1-Apr-17 7:59am    
More likely it's that you need to work out the correct connections strings and use them for the different machines.
Nazneen s 1-Apr-17 8:02am    
i did found the connection string but now its regarding entity framework so what am i missing here.
OriginalGriff 1-Apr-17 8:09am    
:laugh:
How would I know? I can't even see your computer, let alone see what it's doing!

What have you found out with the debugger so far?
Nazneen s 1-Apr-17 8:44am    
ya that was me talking to myself i get error at client machine that entity framework = 6.0.0.0 is not there so i copied them from my machine now the error has changed so what i am gonna do is make new report with keeping in mind about this entity framework.Exhausted though

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900