2

Here is the scenario.I'm creating a desktop application with VB.NET (Windows Forms), and using SQL Server 2008 R2 for its database.

I have two computers (PC1 and PC2) and I want to connect PC2 to PC1.

PC 1 has the SQL Server database. What I do is I just copied .exe application in the debug folder of my vb project and create a notepad for its connection and put them into one folder and transferred it to PC2.

When I run my application to other PC, I get an error

Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue, If you click quit, The application will close immediately.

Cannot open database "DatabaseName" requested by the login. The Login failed. Login failed for user

My code inside the notepad

Data Source=.;Initial Catalog=DBSAS;Integrated Security=True

What I have done so far is to enable remote connection of SQL Server 2008 R2.

Can someone please give me an advice about this? I am really confused. Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Diether Silverious
  • 199
  • 1
  • 5
  • 23
  • DataSource=. declares that SQL Server is on the same machine. Try with SQL Server Instance name instead of . – shadow May 02 '16 at 11:10
  • Are you able to connect to PC1 from PC2 using SSMS or some other tool to verify it's actually accessible? – Shawn May 02 '16 at 11:19

3 Answers3

1

Specify Data Source=PC1 in the connection string. The . indicates a local SQL Server instance running on the same machine as the application. The error suggests SQL Server is installed on PC2 but doesn't contain the desired database.

EDIT:

The error

Cannot open database "DatabaseName" requested by the login

indicates authentication was successful to the SQL Server but the database context could not be set. If DatabaseName in the error message is the same one as the Initial Catalog in the connection string, then either the database does not exist or the user does not have permissions to use it. However, if the DatabaseName in the error message differs from the connection string, the connection string you changed is not the same one that is actually being used by the application.

Dan Guzman
  • 43,250
  • 3
  • 46
  • 71
  • i got the same error when changing to `Data Source=PC1` I just put that connection in a notepad. Is that right? – Diether Silverious May 02 '16 at 03:23
  • @DietherSilverious, yes, you can edit the connection string using the text editor of your choice. Verify the application is actually using that connection string (i.e. it is not hard-coded). – Dan Guzman May 02 '16 at 12:00
1

Hi please find sql server instance name at PC 1 using below command

OSQL -L

replace . to the instance name at you connection string. Specify Data Source= "sql server instance name " in the connection string.

more detail are posted on below link.

How can I determine installed SQL Server instances and their versions?.

Community
  • 1
  • 1
sandeep rawat
  • 4,797
  • 1
  • 18
  • 36
1

On the second pc create a txt file on desktop. Something like test.txt. Then rename it to test.udl Universal Data Link. Double click the test.udl. From there you can produce a valid connection string to the SQL Server. After you are done open the udl file with notepad to get the connection string. Hope this helps.

shadow
  • 1,883
  • 1
  • 16
  • 24
  • I have followed your instructions but i have error `Login failed for user 'PC1/Guest` Can you help me on how to solve this. Thanks for your advice. – Diether Silverious May 03 '16 at 04:58
  • I would first try to connect as `sa` (system administrator). Not with integrated security. – shadow May 03 '16 at 09:17