Wrox Programmer Forums
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 16th, 2007, 12:46 AM
Registered User
 
Join Date: Jan 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Database connection

I've just downloaded VB 2005 Express and SQL server 2005 express. Built SQL server database and trying to connect and open DB.My code is:
Public p_conFirst As New SqlConnection()
 p_conFirst.ConnectionString = "Server=bk\;Database=First;Trusted_Connection=True ;"
p_conFirst.Open()
        'error 4060
I was trying different connectionStrings,reinstall
Sql server, but have the same message:” Can not
open database".It's only with SQL server DB.
Maybe somebody have answer
Thanks, Boris



 
Old January 16th, 2007, 12:19 PM
Authorized User
 
Join Date: Dec 2006
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It could be several issues.
Post the full error message.

You can test connectivity using a UDL file. The test will be for OLE DB and not ADO.NET. At least you will know if you can connect...

Adam Gossage
Lake Wylie, SC, USA
 
Old January 16th, 2007, 12:41 PM
Registered User
 
Join Date: Jan 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,Adam
Message is;"Login failed for bk\boris kofman.Cannot open database "First" requested by the login.The login failed".What is UDL?
Boris

 
Old January 16th, 2007, 01:10 PM
Authorized User
 
Join Date: Dec 2006
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You need to make sure your account 'bk\boris kofman' is a user of the SQL Server and/or database. Check the SQL Server logins and make sure your account has the appropriate permissions for the catalog 'First'. If you cannot find your username, add your account in SQL. Or, since the BUILTIN\Administrators group has been added by default, add your account as administrator of the machine.

A UDL file is a data link file that is used for connecting to a database and testing database connectivity. Think of it as a DSN in ODBC. You can create a UDL by creating a Text Document and renaming it with a .UDL extension. Launch the UDL file to open a properties dialog, test, etc. Once you test successfully with the UDL file, click OK on the UDL properties dialog and reopen the file in Notepad. The file will contain a working connection string for a given provider.


Adam Gossage
Lake Wylie, SC, USA
 
Old January 16th, 2007, 09:37 PM
Registered User
 
Join Date: Jan 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes,I have account as administrator.'Boris kofman'is the name of server,'bk' is the name of machine.I'm still not sure if this account is a user...How and
where,step by step,can I check SQL Server login?

 
Old January 17th, 2007, 10:45 AM
Authorized User
 
Join Date: Dec 2006
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Your best bet is to use the SQL Server Management Studio. There are other methods for managing logins, but are more difficult for users learning. If you have not already installed the SQL Server Management Studio, you can download from http://msdn.microsoft.com/vstudio/express/sql/download/.

1. Launch SQL Server Management Studio
2. Open the Registered Servers via the View menu
3. Expand Database Engine
4. If no servers are listed, right click on Database Engine and click on 'Update Local Server Registration'.
5. If still no servers are listed, the SQL Windows Service needs to be started. You should only have one service for SQL Express.
6. If the server exists, right click the server and click on Connect:Object Explorer.
7. In the Object Explorer, expand Security:Logins.
8. You should have at least two accounts, BUILTIN\Administrators and sa.
9. You can add new users by right clicking on Logins, then New Login.
10. Unless the user has been assigned the sysadmin system role, you must grant permission to one or more catalogs. Catalog permissions are found in the user properties dialog in the User Mappings tab.



Adam Gossage
Lake Wylie, SC, USA
 
Old January 17th, 2007, 12:58 PM
Registered User
 
Join Date: Jan 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

First thanks for you patience.Only could not find User
Mapping tab.But anyway I still have the same problem.
Maybe VISUAL Basic 2005 'express' can only bind SQL DB

Boris

 
Old January 17th, 2007, 01:32 PM
Authorized User
 
Join Date: Dec 2006
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No problem. The issue is still a connectivity issue with SQL. From a database connectivity stand point, VB 2005 Express is fully functional.

What logins are listed in SQL Management Studio?
You should see at least BUILTIN\Administrators. If you see BUILTIN\Administrators, right click on the login and click on properties. Make sure the sysadmin check box is checked under 'Server Roles'.

The problem may be that your account is not in the sysadmin Server Role.
Do you remember when you installed SQL whether you set Server Authentication to 'SQL Server and Windows Authentication mode("Mixed Mode"). By default, Server Authentication is set to Windows Authentication mode, not mixed. If you did, you can login as 'sa'. If not, you may want to reinstall and set the Server Authentication to mixed mode.






Adam Gossage
Lake Wylie, SC, USA
 
Old January 17th, 2007, 01:35 PM
Authorized User
 
Join Date: Dec 2006
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Forgot, when you open the login properties dialog, the User Mappings page will contain the databases permissions for that user. If the BUILTIN\Administrators group is not in the sysadmin Server Role, see if you can add a User Mapping for the database you want to connect.

Adam Gossage
Lake Wylie, SC, USA
 
Old January 18th, 2007, 12:41 AM
Registered User
 
Join Date: Jan 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,Adam
Same story
as you said I reinstall server with mixed mode,checked again management Studio settings.There are two options:Windows and
SQL Server Authentication.this time I choose second.Login is 'sa'
Again my connection code is:
 Public p_conFirst As New OleDb.OleDbConnection()
 p_conFirst.ConnectionString = "Provider=SQLOLEDB;Data Source=bk\SQLEXPRESS;" & _
        "Database=pubs;User ID=sa;Password=borkof"
p_conFirst.Open()
Same message "Cannot open Database 'First' requested by login.
login failed"
Maybe you will make corrections in code
 Boris






Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Connection to Access Database reachsevar ASP.NET 2.0 Basics 1 November 28th, 2007 08:56 AM
Database Connection oneillg PHP Databases 1 October 17th, 2007 04:48 PM
Database Connection kapi.goel SQL Language 2 February 14th, 2006 07:01 PM
database connection Nitin_sharma Classic ASP Databases 1 February 8th, 2005 10:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.