尝试读取或写入受保护的内存。这通常表明其他内存已损坏 [英] Attempted to read or write protected memory. This is often an indication that other memory has been corrupted
本文介绍了尝试读取或写入受保护的内存。这通常表明其他内存已损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在通过代码创建ODBC连接,但它给了我上面的错误。下面是我的代码:
I am creating ODBC connection through code but it gives me the above error.Below is my code:
Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" ( _
ByVal hwndParent As Long, ByVal fRequest As Long, _
ByVal lpszDriver As String, ByVal lpszAttributes As String) As Long
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim DsnName As String = "Search1"
Dim PathDB As String = "E:\Rachna\LocalityDd.mdb"
Dim UID As String = ""
Dim PAssWord As String = ""
Const ODBC_ADD_DSN = 1 'Add User DSN
Dim rl As Long
Dim Strsetting As String = ""
Strsetting = Strsetting + "dsn=" & DsnName
Strsetting = Strsetting + ";" + "DBQ=" & PathDB '& Chr(0) & Strsetting
Strsetting = Strsetting + ";" + "uid=" & UID '& Chr(0) & Strsetting
Strsetting = Strsetting + ";" + "pwd=" & PAssWord '& Chr(0) & Strsetting
rl = SQLConfigDataSource(0&, ODBC_ADD_DSN, "Microsoft Access Driver (*.mdb)", Strsetting)
If rl = 1 Then
MsgBox("Created ODBC")
Else
MsgBox("Error")
End If
End Sub
可以任意1请帮我纠正错误吗?
提前致谢。
Can any1 please help me to rectify the error??
Thanks in advance.
推荐答案
Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" ( _
ByVal hwndParent As Int32, ByVal fRequest As Int32, _
ByVal lpszDriver As String, ByVal lpszAttributes As String) As Int32
刚用Int32取代Long,它解决了我的问题..
Just replaced Long with Int32 and it solved my problem..
这篇关于尝试读取或写入受保护的内存。这通常表明其他内存已损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文