简体   繁体   English

VBScript和SQL Server 2008问题

[英]VBScript and SQL Server 2008 Questions

So I don't know much about SQL or VBScript, much less putting the two together. 所以我对SQL或VBScript不太了解,更不用说将两者结合在一起了。

I'm trying to connect to a SQL Server running SQL 2008. All I want to do is connect and I can't seem to do it. 我正在尝试连接到运行SQL 2008的SQL Server。我要做的就是连接,但我似乎做不到。 I keep getting various errors, including: 我不断收到各种错误,包括:

  • "Data source name not found and no default driver specified" “找不到数据源名称,并且未指定默认驱动程序”
  • "Login failed for user 'user'" “用户“ user”的登录失败”
  • "Invalid character" “无效字符”

I already know about http://www.connectionstrings.com but I don't know what a number of things mean. 我已经知道http://www.connectionstrings.com,但是我不知道这意味着什么。 What is a Data Source? 什么是数据源? What is an Initial Catalog? 什么是初始目录?

Here is what I have so far. 这是我到目前为止所拥有的。

Dim result
Set cn = CreateObject("ADODB.Connection")
cn.ConnectionString = "Provider=SQLOLEDB.1;Server=MyIP;Database=SQLDatabase;User ID=user;Password=pass"
cn.Open
strQry = "select * from Users"
set result = cn.execute(strQry)

Can someone help me make heads and tails of this? 有人可以帮我做这个的正面和反面吗?

Edit 1: This is what I am seeing in the Server Configuration Manager; 编辑1:这就是我在服务器配置管理器中看到的;

在此处输入图片说明

Edit 2: I apologize for not making this clear. 编辑2:很抱歉,我没有明确说明。 I am not connecting to the local machine. 我没有连接到本地计算机。 I am connecting to a machine on my network. 我正在连接到网络上的计算机。

Data Source = the instance of the database engine you are connecting to, either a host name or a host name combined with a named instance. 数据源=您要连接到的数据库引擎的实例,可以是主机名或与命名实例组合的主机名。 Often this is localhost or localhost\\SQLEXPRESS but it can also be an IP address or fully-qualified domain name (either inside or outside your network). 通常这是localhostlocalhost\\SQLEXPRESS但也可以是IP地址或完全限定的域名(在网络内部或外部)。

Initial Catalog = database to connect to. 初始目录=要连接的数据库。 The login associated with the username/password used in the connection string must be in specific server roles or be associated with a user in the database that at least belongs to the public role. 与连接字符串中使用的用户名/密码关联的登录名必须具有特定的服务器角色,或者必须与数据库中至少属于公共角色的用户关联。

If you've installed SQL Server Express Edition, your connection string should be: 如果已安装SQL Server Express Edition,则连接字符串为:

cn.ConnectionString = "Provider=SQLNCLI10;" & _
  "Data Source=myIP\SQLExpress;" & _
  "Initial Catalog=SQLDatabase;" & _
  "User ID=user;Password=pass"

We can't know for sure if that is the correct connection string - if you've installed a default instance or you named your instance something else, for example. 我们不确定这是否是正确的连接字符串-例如,如果您安装了默认实例或为实例命名了其他名称。 Other variations you might try (since you said you didn't install Express), in case there is some problem with myIP : 万一myIP出现问题,您可以尝试其他变体(因为您说过没有安装Express):

"Data Source=localhost;" & _

Or 要么

"Data Source=(local);" & _

Or 要么

"Data Source=.;" & _

Or 要么

"Data Source=127.0.0.1;" & _

To see what you have actually installed, you can go to Start > All Programs > SQL Server 2008 > Configuration Tools > SQL Server Configuration Manager and click on SQL Server Services. 要查看实际安装的内容,可以转到“开始”>“所有程序”>“ SQL Server 2008”>“配置工具”>“ SQL Server配置管理器”,然后单击“ SQL Server服务”。 In the right pane, you should see something like this: 在右侧窗格中,您应该看到类似以下内容:

在此处输入图片说明

Though your instance names may not match mine. 虽然您的实例名称可能与我的不匹配。 If you see SQL Server (MSSQLSERVER) , this is a default instance, and the data source in your connection string would be . 如果看到SQL Server (MSSQLSERVER) ,则这是默认实例,并且连接字符串中的数据源将是. or (local) or (localhost) . (local)(localhost) If you see SQL Server (something other than MSSQLSERVER) then it would be .\\something other than MSSQLSERVER etc. You can also see whether the instance is running, which might be another problem. 如果看到SQL Server (something other than MSSQLSERVER) ,它将是.\\something other than MSSQLSERVER等等。您还可以查看实例是否正在运行,这可能是另一个问题。 If the instance you want to connect to is stopped, you won't be able to connect to it until you right-click and choose Start. 如果要连接的实例已停止,则必须先右键单击并选择“启动”,然后才能连接到该实例。 You might also want to right-click the instance and select Properties so that you can set the service to start automatically, so you don't have to repeat this process the next time you reboot. 您可能还需要右键单击该实例,然后选择“属性”,以便可以将服务设置为自动启动,因此下次重新启动时不必重复此过程。 If you want the service to be running all the time. 如果您希望服务一直运行。

If you show us what you see in the configuration manager we can help with the exact connection string you need. 如果您向我们展示在配置管理器中看到的内容,我们可以为您提供所需的确切连接字符串的帮助。

EDIT 编辑

Now that I see the updated error message, which contains: 现在,我看到了更新的错误消息,其中包含:

[DBNETLIB][ConnectionOpen (Connect()).]

You might try a few options: 您可以尝试以下几种方法:

(1) make sure TCP/IP is enabled. (1)确保启用了TCP / IP。 In the configuration manager, under SQL Server Network Configuration > Protocols for MSSQLSERVER, right-click TCP/IP, and choose Enable. 在配置管理器中的“ SQL Server网络配置”>“ MSSQLSERVER的协议”下,右键单击“ TCP / IP”,然后选择“启用”。 You'll need to restart SQL Server. 您需要重新启动SQL Server。 (While you should be able to use shared memory, this is how I used to always configure classic ASP.) (虽然您应该能够使用共享内存,但是这是我以前始终配置经典ASP的方式。)

(2) add the following to your connection string: (2)将以下内容添加到您的连接字符串中:

cn.ConnectionString = "Provider=SQLNCLI10;" & _
  "Data Source=localhost;" & _
  "Initial Catalog=SQLDatabase;" & _
  "User ID=user;Password=pass;" & _
  "Network=DBMSSOCN;"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM