无DSN的ODBC问题 [英] DSN-less ODBC questions

查看:103
本文介绍了无DSN的ODBC问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于ODBC的两个问题。


1)我使用以下代码连接到MySQL数据库:


函数LoginToMySQL(sUsername As String,sPW As String)As Boolean

Dim dbMySQL As Data

Dim cnMySQL As DAO.Connection

Dim sDSN As String

sDSN =" ODBC; DRIVER = {MySQL ODBC 3.51 Driver};" _

& " SERVER = 127.0.0.1;" _

& " DATABASE = LIMS;" _

& " UID = QUOT; &安培; sUsername&英寸; PWD =" &安培; sPW _

& " ;; OPTION = 16386"

设置dbMySQL = OpenDatabase("",dbDriverNoPrompt,sDSN)

结束功能


当我进入OpenDatabase调用时,系统会提示我选择现有的

DSN。我希望能够建立无DSN连接。这是

可能吗?是特定于驱动程序吗?任何人都可以推荐的代码更改?


2)通过ODBC& amp; DAO进入一个带有

自动编号主键的表,我希望在插入后获得新的主要

键的值。使用ADO和Jet,可以使用SELECT

@@ IDENTITY。检索此值。如何使用DAO和ODBC获取

插入记录的自动编号?


非常感谢任何一个问题的想法或答案。


干杯,

Eric

Two questions regarding ODBC.

1) I am connecting to a MySQL database using the following code:

Function LoginToMySQL(sUsername As String, sPW As String) As Boolean
Dim dbMySQL As Database
Dim cnMySQL As DAO.Connection
Dim sDSN As String
sDSN = "ODBC;DRIVER={MySQL ODBC 3.51 Driver};" _
& "SERVER=127.0.0.1;" _
& " DATABASE=lims;" _
& "UID=" & sUsername & ";PWD=" & sPW _
& ";OPTION=16386"
Set dbMySQL = OpenDatabase("", dbDriverNoPrompt, , sDSN)
End Function

When I get to the OpenDatabase call, I am prompted to chose an existing
DSN. I would like to be able to make the connection DSN-less. Is this
possible? Is it driver specific? Any code changes anyone can recommend?

2) When inserting a record via ODBC & DAO into a table with an
autonumber primary key, I would like to get the value of the new primary
key after insert. Using ADO and Jet, it''s possible to use "SELECT
@@IDENTITY" to retrieve this value. How can I get the autonumber of the
inserted record using DAO and ODBC?

Many thanks for any ideas or answers to either question.

Cheers,

Eric

推荐答案



Eric E <,E @ A>在消息新闻中写道:po ******************** @ speakeasy.net ...

"Eric E" <e@a> wrote in message news:po********************@speakeasy.net...
关于ODBC的两个问题。

1)我使用以下代码连接到MySQL数据库:

函数LoginToMySQL(sUsername As String,sPW As String)As Boolean
Dim dbMySQL As Database
Dim cnMySQL As DAO.Connection
DDS sDSN As String
sDSN =" ODBC; DRIVER = {MySQL ODBC 3.51 Driver};" _
& " SERVER = 127.0.0.1;" _
& " DATABASE = LIMS;" _
& " UID = QUOT; &安培; sUsername&英寸; PWD =" &安培; sPW _
& " ;; OPTION = 16386"
设置dbMySQL = OpenDatabase("",dbDriverNoPrompt,sDSN)
结束功能

当我进入OpenDatabase调用时,我是提示选择现有的DSN。我希望能够建立无DSN连接。这可能吗?是特定于驱动程序吗?任何人都可以推荐任何代码更改?

2)通过ODBC& amp; DAO进入一个带有
自动编号主键的表,我希望在插入后得到新的主键值。使用ADO和Jet,可以使用SELECT
@@ IDENTITY。检索此值。如何使用DAO和ODBC获取
插入记录的自动编号?
Two questions regarding ODBC.

1) I am connecting to a MySQL database using the following code:

Function LoginToMySQL(sUsername As String, sPW As String) As Boolean
Dim dbMySQL As Database
Dim cnMySQL As DAO.Connection
Dim sDSN As String
sDSN = "ODBC;DRIVER={MySQL ODBC 3.51 Driver};" _
& "SERVER=127.0.0.1;" _
& " DATABASE=lims;" _
& "UID=" & sUsername & ";PWD=" & sPW _
& ";OPTION=16386"
Set dbMySQL = OpenDatabase("", dbDriverNoPrompt, , sDSN)
End Function

When I get to the OpenDatabase call, I am prompted to chose an existing
DSN. I would like to be able to make the connection DSN-less. Is this
possible? Is it driver specific? Any code changes anyone can recommend?

2) When inserting a record via ODBC & DAO into a table with an
autonumber primary key, I would like to get the value of the new primary
key after insert. Using ADO and Jet, it''s possible to use "SELECT
@@IDENTITY" to retrieve this value. How can I get the autonumber of the
inserted record using DAO and ODBC?




由于您没有提供数据库,因此提示您名称。


如果您通过DAO .AddNew,.Update输入新记录,您可以使用.Bookmark = .LastModified移至新记录

。如果没有,我相信你

必须发出一个Select查询来检索你刚插入的记录。



You''re being prompted because you''re not supplying a database name.

If you enter a new record via DAO .AddNew, .Update you can move to
the new record using .Bookmark = .LastModified. If not, I believe you
have to issue a Select query to retrieve the record you just inserted.


谢谢快速回答,rkc。我不得不承认我很困惑:


没有DATABASE = lims指定数据库?

我是否需要它周围的报价或其他一些?


至于添加新记录,我会试试。谢谢。


EE

rkc写道:
Thanks for the quick answers, rkc. I have to admit I''m confused:

Doesn''t "DATABASE=lims" specify the database?
Do I need quotes around it or some such?

As for the adding a new record, I will try that. Thanks.

EE
rkc wrote:
" Eric E" <,E @ A>在消息新闻中写道:po ******************** @ speakeasy.net ...
"Eric E" <e@a> wrote in message news:po********************@speakeasy.net...
关于ODBC的两个问题。

1)我使用以下代码连接MySQL数据库:

函数LoginToMySQL(sUsername As String,sPW As String)As Boolean
Dim dbMySQL As数据库
Dim cnMySQL As DAO.Connection
DDS sDSN As String
sDSN =" ODBC; DRIVER = {MySQL ODBC 3.51 Driver};" _
& " SERVER = 127.0.0.1;" _
& " DATABASE = LIMS;" _
& " UID = QUOT; &安培; sUsername&英寸; PWD =" &安培; sPW _
& " ;; OPTION = 16386"
设置dbMySQL = OpenDatabase("",dbDriverNoPrompt,sDSN)
结束功能

当我进入OpenDatabase调用时,我是提示选择现有的DSN。我希望能够建立无DSN连接。这可能吗?是特定于驱动程序吗?任何人都可以推荐任何代码更改?

2)通过ODBC& amp; DAO进入一个带有
自动编号主键的表,我希望在插入后得到新的主键值。使用ADO和Jet,可以使用SELECT
@@ IDENTITY。检索此值。如何使用DAO和ODBC获取
插入记录的自动编号?
Two questions regarding ODBC.

1) I am connecting to a MySQL database using the following code:

Function LoginToMySQL(sUsername As String, sPW As String) As Boolean
Dim dbMySQL As Database
Dim cnMySQL As DAO.Connection
Dim sDSN As String
sDSN = "ODBC;DRIVER={MySQL ODBC 3.51 Driver};" _
& "SERVER=127.0.0.1;" _
& " DATABASE=lims;" _
& "UID=" & sUsername & ";PWD=" & sPW _
& ";OPTION=16386"
Set dbMySQL = OpenDatabase("", dbDriverNoPrompt, , sDSN)
End Function

When I get to the OpenDatabase call, I am prompted to chose an existing
DSN. I would like to be able to make the connection DSN-less. Is this
possible? Is it driver specific? Any code changes anyone can recommend?

2) When inserting a record via ODBC & DAO into a table with an
autonumber primary key, I would like to get the value of the new primary
key after insert. Using ADO and Jet, it''s possible to use "SELECT
@@IDENTITY" to retrieve this value. How can I get the autonumber of the
inserted record using DAO and ODBC?



由于您没有提供数据库名称,因此提示您。 />
如果您通过DAO .AddNew,.Update输入新记录,您可以使用.Bookmark = .LastModified转到新记录。
如果没有,我相信你必须发出一个Select查询来检索你刚刚插入的记录。


You''re being prompted because you''re not supplying a database name.

If you enter a new record via DAO .AddNew, .Update you can move to
the new record using .Bookmark = .LastModified. If not, I believe you
have to issue a Select query to retrieve the record you just inserted.





" Eric Ellsworth" < EZ @ e基在留言中写道

新闻:Pq ******************** @ speakeasy.net ...

"Eric Ellsworth" <ez@e> wrote in message
news:Pq********************@speakeasy.net...
谢谢快速回答,rkc。我不得不承认我很困惑:

并不是DATABASE = lims指定数据库?
我是否需要引用它或其他一些?
Thanks for the quick answers, rkc. I have to admit I''m confused:

Doesn''t "DATABASE=lims" specify the database?
Do I need quotes around it or some such?




您会认为那不是吗?


尝试从sDSN字符串中取出数据库名称,并将其添加到OpenDatabase方法的第一个参数




You would think that wouldn''t you?

Try taking the database name out of the sDSN string and adding it to the
first argument of OpenDatabase method.


这篇关于无DSN的ODBC问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆