2
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
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
You can use app.config & write below code like
- <connectionStrings>
- <add name="xxxs_ADO" providerName="System.Data.SqlClient" connectionString="Data Source=xxx;Initial Catalog=DBName;User ID=sa;Password=xxxxxx" />
- </connectionStrings>
OR
Use <appSetting> attribute
- <appString>
- <add key="DBName" value="XXXX" />
- <add key="Initial Catalog" value="XXXX" />
- <add key="Server Name" value="XXXX" />
- <add key="Password" value="XXXX" />
- </appString>
0
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
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
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
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
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
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
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
Can you share your connection string and screenshot of error (if possible)
0
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
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
Donot hard code the connection string, use the config file to store and access from it.