Thursday, February 16, 2012

ASP.Net with SQL-DMO

Any help is appreciated!

I try to convert a VB 6 program to ASP.Net.

The original vb 6 program uses SQL-DMO to gather information from SQL Servers using 'Microsoft SQLDMO Object Library':

vb6:
Referenced te DMO inside VB 6
Dim oSQLSvr2 As New SQLServer2

ASP.Net:

I got Compiler Error Message: BC30002: Type 'SQLServer2' is not defined.

ASP.Net source code:

<%@. Page Language="VB" Debug="TRUE" %>
<%@. Import namespace="System.Data" %>
<%@.Import namespace="System.Data.OLeDb"%>
<%@.Import namespace=""sqldmo"%>
<%@.Import namespace=""sqldmo.SQLServer2"%
<script runat="Server">
Sub btn_Click(S As Object, e As EventArgs)
Dim oSQLSvr2 as New SQLServer2

oSQLSvr2.LoginTimeout = 30
oSQLSvr2.LoginSecure = True
oSQLSvr2.Connect "ORGDEV03"
End Sub
</Script
<html>
<head><title>test
</title></head>
<body>
<form runat="Server">
Title
<p/>
<asp:Button Text="Connect to SQL Server" OnClick="btn_Click" Runat="Server"/
</form>
</body
</html>There is no namespace called sqldmo.SQLServer2, so you should remove that @.Import namespace line.

Instead of this:

Dim oSQLSvr2 as New SQLServer2
use this
Dim oSQLSvr2 AS New SQLDMO.SQLServer2

Terri|||It is still doesn't work. Any help?|||I tried the exact code following and it works fine on my machine (one thing I did notice with your code is that you can an extra double quote in your Import namespace="sqldmo" directive):


<%@. Page Language="VB" Debug="TRUE" %>
<%@. Import namespace="System.Data" %>
<%@. Import namespace="System.Data.OLeDb"%>
<%@. Import namespace="sqldmo"%
<script runat="Server">
Sub btn_Click(S As Object, e As EventArgs)
Dim oSQLSvr2 as New SQLDMO.SQLServer2

oSQLSvr2.LoginTimeout = 30
oSQLSvr2.LoginSecure = True
oSQLSvr2.Connect("(local)")
End Sub
</Script
<html>
<head><title>test
</title></head>
<body>
<form runat="Server" ID="Form1">
Title
<p/>
<asp:Button Text="Connect to SQL Server" OnClick="btn_Click" Runat="Server" ID="Button1" NAME="Button1"/
</form>
</body
</html>

Terri|||Terri,

I am not using VS.Net Environment to create the ASP.net Page. That's why mine doesn't work.

The sqldmo.dll (referenced in my code) is a COM object(not .Net Assembly) so that the namespace is not imported in my code.

To resolve this problem, I copy and paste my code in VS.Net and compile it. Then copy the \bin\Interop.sqldmol.dll to my ASP.Net application root directory. It works fine.

Thank again.

Pak

No comments:

Post a Comment