connection string to data base
-
24. září 2012 21:20
Hi,
I am using sql server 2008 r2 and I have no problem with connecting to MS SQL server management studio
with the following paramaters:
Server type: Database Engine
Server name: STAMPC\SQL2008
Authentication: SQL Server Authentication
Login: sa
Password: abcde
Then, I am able to edit the first 100 rows of the table DISKREL.
However, I cannot connect to the data base with the following vbscript:
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")objConnection.Open _
"Provider=SQLOLEDB;Data Source=STAMPC\SQL2008;" & _
"Initial Catalog=DISKREL;" & _
"User ID=sa;Password=abcde;"I get the following error:
Script: c:\a.vbs
Error: Cannot open database "DISKREL" requested by the login. The login failed.
Code: 80004005
Source: Microsoft OLE DB Provider for SQL Server
What did I do wrong in the script?
Všechny reakce
-
24. září 2012 21:50
Initial Catalog should be database name not table. You may open the table using the objRecordSet and some SQL statement depending on your action.
http://www.connectionstrings.com/sql-server-2008
Some examples here.
http://gallery.technet.microsoft.com/scriptcenter/site/search?f%5B0%5D.Type=RootCategory&f%5B0%5D.Value=databases&f%5B0%5D.Text=Databases&f%5B1%5D.Type=SubCategory&f%5B1%5D.Value=sqlserver&f%5B1%5D.Text=SQL%20Server
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows]
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights. -
24. září 2012 21:55Moderátor
Hello,
Please, could you have a look at ?
or ( maybe better ) http://social.msdn.microsoft.com/Forums/eu/sqlexpress/thread/db707fab-d2aa-49fc-88a7-ba9c0749c2fc
I am thinking that there is an error in the name of the database
Have a nice day
PS : SQL Server 2008 accepts to have a database name terminated by a space which is included in the name ( i have fallen in this trap yesterday )
Mark Post as helpful if it provides any help.Otherwise,leave it as it is.
- Upravený Papy NormandModerator 24. září 2012 21:57 PS added
-
24. září 2012 22:07
Sorry,
I made an error in the above posting, DISKREL is the database name, not the table name. However, I am still getting this error.
The correct post should be:
"I am able to edit the first 100 rows of the table RelTable_TAD of data base DISKREL."
-
25. září 2012 13:38Check the sql server error log for login failure details & share the same .
Regards,
Rohit Garg
(My Blog)
This posting is provided with no warranties and confers no rights.
Please remember to click Mark as Answerand Vote as Helpfulon posts that help you. This can be beneficial to other community members reading the thread.
- Upravený RohitGargMicrosoft Community Contributor 25. září 2012 13:39
-
25. září 2012 14:08Moderátor
Set objConnection = CreateObject("ADODB.Connection") Set objRecordSet = CreateObject("ADODB.Recordset") objConnection.ConnectionString = "Provider=SQLOLEDB;Data Source=STAMPC\SQL2008;" & _ "Initial Catalog=DISKREL;" & _ "User ID=sa;Password=abcde;" objConnection.Open
Hello,
I would suggest you to modify your code to get the connection string and to use it in SSMS ( in your connection form of SSMS, you have only to click on the 3rd button labelled Options >> , in the new form , click on the 3rd tabpage labelled like More conections parameters and you copy the connection string into the textbox, click on the Connect button ). The proposed code is just before the Hello ( an error from myself )
If you get an error with this connection string , you will have an error messagebox.Click on the 3rd icon ( with the mouse on it , you should see something like Display technical details and in the new form , click on the little icon at the bottom ( Copy the message text ) and post it with the contain of the connection string. It could eliminate a problem in the connection string.
I am sorry and i hope you will excuse me , but having a french SSMS, i am not sure about the translation of what i am seeing.
We are waiting for your feedback to try to help you more efficiently.
Have a nice day
Mark Post as helpful if it provides any help.Otherwise,leave it as it is.
- Označen jako odpověď Iric WenModerator 2. října 2012 8:05