15
Answers

Database Path change

Photo of siddu benagal

siddu benagal

8y
965
1
Hi
 
 I have developed one windows application and now i want to run that application in other system,but here my doubt is ... how to give path(connectio string) for DB to run the application in other system...? 

Answers (15)

2
Photo of Amit Gupta
NA 22.9k 248.1k 8y
Hey
 
If you are running Sql Server then use . (Dot), it determine the current user 
Put in the DataSource/Server = . 
 
If you are running Sql Server Express then put in the DataSource/Server =.\InstanceName 
 
Where InstanceName is SqlExpress
 
Check reference
https://www.connectionstrings.com/sql-server/ 
1
Photo of Amit Gupta
NA 22.9k 248.1k 8y
Connection string is correct, There are several other reasons while attaching the mdf file.
 
Please ensure the following points:
1. The Data Directory is not compressed
2. Run the application as an administrator
3. mdf file is valid. 
 
 
Do let me know, if this works ! 
0
Photo of Thiruppathi R
NA 7.3k 2.4m 7y
You can use app.config & write below code like 
 
  1. <connectionStrings>    
  2.    <add name="xxxs_ADO" providerName="System.Data.SqlClient" connectionString="Data Source=xxx;Initial Catalog=DBName;User ID=sa;Password=xxxxxx" />    
  3.  </connectionStrings>    
OR
 
Use <appSetting> attribute
 
  1. <appString>  
  2. <add key="DBName" value="XXXX" />  
  3. <add key="Initial Catalog" value="XXXX" />  
  4. <add key="Server Name" value="XXXX" />  
  5. <add key="Password" value="XXXX" />  
  6. </appString>  
 
 
 
 
 
0
Photo of Rafnas T P
143 13.4k 4.5m 8y
read this link below, you wil get some idea
 
http://stackoverflow.com/questions/12266924/how-do-i-read-the-current-path-of-datadirectory-from-config-settings 
0
Photo of siddu benagal
NA 33 5.1k 8y
no i am not using remote server ,i am using local db
and if i give full path means it wil work bt when it comes to Datadirectory its throwing error 
0
Photo of Amit Gupta
NA 22.9k 248.1k 8y
How suddenly the exception changed?
 
1. From where you are accessing the mdf file, is it from a LAN?
 
2. Try adding User Instance =True; to the connection string. 
 
3. If the DataDirectory in your connection string is not working then try to give the full path of the file and try again. 
 
4. If above points are not working then open ssms check your database, make sure it was not in recovery pending mode 
 
Hope this will help you to get your issue resolved 
0
Photo of siddu benagal
NA 33 5.1k 8y
An attempt to attach an auto-named database for file failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
 
 
same problem is coming again and again.... 
0
Photo of Amit Gupta
NA 22.9k 248.1k 8y
Try restarting SQL Server instance or follow the link
http://www.dotnetfunda.com/forums/show/9225/sql-server-a-connection-was-successfully-established-with-the-server-b 
0
Photo of siddu benagal
NA 33 5.1k 8y
Now  i am getting this error 
A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.)
 
0
Photo of Amit Gupta
NA 22.9k 248.1k 8y
Change to this
  1. <add name="ConString" connectionString="Data Source=.;Integrated Security=True;AttachDbFilename=|DataDirectory|database1.mdf;"  
  2. providerName="System.Data.sqlClient"/>  
 
0
Photo of siddu benagal
NA 33 5.1k 8y
this is the my connection string
<add name="ConString" connectionString="Data Source=.\;Integrated Security=True;AttachDbFilename=|DataDirectory|database1.mdf;"
providerName="System.Data.sqlClient"/>
 
 and i am using sql server 2008 r2 
 
0
Photo of Amit Gupta
NA 22.9k 248.1k 8y
Can you share your connection string and screenshot of error (if possible)
0
Photo of siddu benagal
NA 33 5.1k 8y
Hi amit i have tried according to you bt i am getting below  this error 
 
The user instance login flag is not supported on this version of SQL Server. The connection will be closed.
0
Photo of Satyendra Patel
NA 984 393.8k 8y
hii,
 
It is not so complex ,it is simple.firstly you set the connection string in your application.For Example your database path is( C/Database /localDB) in your system.when you want to run your application on another system then your data base are save as it(C/Database /localDB)like as your local system.
0
Photo of Amit Gupta
NA 22.9k 248.1k 8y
Donot hard code the connection string, use the config file to store and access from it.