Error when running ASP.NET Web Site of SQL error - asp.net

Alright so I'm building an ASP.NET web site, currently creating the log in form however I keep getting an error that I am unable to attach a SQL Server file.
I did some research and found I needed to create an app_data folder in my directory which I did, and in that folder now there are 3 .mdf files (SQL Server primary data files) which I cannot open in SQL Server Management Studio.
Looks like similar problems are solved by fixing a connection to a SQL Server. However, in my web site I don't have a connection to an SQL Server declared so why is there a SQL Server error? Also attaching the function that is being called
Protected Sub Login1(sender As Object, e As System.EventArgs) Handles loginForm.LoggingIn
Dim bolloginCheck As Boolean
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "alertMessage", "alert(' " & loginForm.UserName.Trim() & " - " & loginForm.Password.Trim() & " ');", True) 'displays localhostsays : called fomrcode-behind directly!
bolloginCheck = _client.Verify_Login(loginForm.UserName, loginForm.Password)
If bolloginCheck = True Then
'set user name Or session variable, adjust to true And authenticated
Response.Redirect("https://www.google.com")
Else
loginForm.FailureText = "Unable to login, please review your login credentials."
End If
End Sub
Public Function Verify_Login(strUsername As String, strPassword As String) As Boolean Implements IService.Verify_Login
Return True
End Function
<ServiceContract()>
Public Interface IService
''WEBSITE FUNCTIONS''
<OperationContract()>
Function Verify_Login(uname As String, pword As String) As Boolean
End Interface
<DataContract()>
Public Class CompositeType
<DataMember()>
Public Property BoolValue() As Boolean
<DataMember()>
Public Property StringValue() As String
End Class
Public Class Service
Implements IService
Public Sub New()
End Sub
Public Function Verify_Login(strUsername As String, strPassword As String) As Boolean Implements IService.Verify_Login
Return True
End Function
End Class
Error:
An attempt to attach an auto-named database for file C:\Users\Dewy\Desktop\TestWebSite\App_Data\aspnetdb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

Related

Create a dataContract in separe file problem

Hi I need to create a class for return the data in WCF service. I followed the web at 5 simple steps to create your first RESTful service. However I get the error for . I searched the web and add the System.Runtime.Serialization.DataContractSerializer, Would someone tell me what should do. I am using VS2015 as the tool to build it. Thanks.
Imports System.Runtime.Serialization
Imports System.Collections.Generic
Imports System.Runtime.Serialization.DataContractSerializer
<DataContract>
Public Class Locations
<DataMember>
Public Property LocationName As String
<DataMember>
Public Property LocationID As Integer
End Class
Could you please share the error details with me?
As you know, we usually use the datacontract to transmit the complex data type which could be recognized by the client-side and server-side. so that the data could be serialized and transmitted normally between different platforms.
For the restful web service in WCF, we need to use the Webhttpbinding build the data channel and add the Webhttpbehavior to the service endpoint.
I have made a demo, wish it is useful to you.
Server-side.
Imports System.Runtime.Serialization
Imports System.ServiceModel
Imports System.ServiceModel.Description
Imports System.ServiceModel.Web
Module Module1
Sub Main()
Dim uri As New Uri("http://localhost:900")
Dim binding As New WebHttpBinding()
binding.CrossDomainScriptAccessEnabled = True
binding.Security.Mode = WebHttpSecurityMode.TransportCredentialOnly
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None
Using sh As New ServiceHost(GetType(MyService), uri)
Dim se As ServiceEndpoint = sh.AddServiceEndpoint(GetType(IService), binding, uri)
se.EndpointBehaviors.Add(New WebHttpBehavior())
sh.Open()
Console.WriteLine("Service is ready")
Console.ReadLine()
sh.Close()
End Using
End Sub
<ServiceContract([Namespace]:="mydomain")>
Public Interface IService
<OperationContract>
<WebGet(ResponseFormat:=WebMessageFormat.Json)>
Function SayHello() As List(Of Product)
End Interface
Public Class MyService
Implements IService
Public Function SayHello() As List(Of Product) Implements IService.SayHello
Dim result = New List(Of Product)() From {
New Product With {
.Id = 1,
.Name = "Apple"
},
New Product With {
.Id = 2,
.Name = "Pear"
}
}
Return result
End Function
End Class
<DataContract([Namespace]:="mydomain")>
Public Class Product
<DataMember>
Public Property Id() As Integer
<DataMember>
Public Property Name() As String
End Class
End Module
Client.
$(function(){
$.ajax({
type:"GET",
url:"http://10.157.18.188:900/sayhello",
dataType:"jsonp",
success:function(d){
$.each(d,function(i,o){
console.log(o.Id);
console.log(o.Name);
})
}
})
})
Result.
Here is an official sample
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-create-a-basic-wcf-web-http-service

Can I use System.Web.UI.Page in console application?

I want to test a function which is in a web page. Do I have way to use System.Web.UI.Page in a console application and put something in Session and test this way?
I created a test class and to inherit the Page but I could not put Session in it. When I type "myPage." as show below, I do not see anything come out after "."
<TestClass()> Public Class UnitTest2
Inherits System.Web.UI.Page
Dim myPage = New System.Web.UI.Page
myPage.
End Class
Please help!
Update: Below code seemed to pass the compiler
<TestClass()> Public Class UnitTest2
<TestMethod()>
Public Sub TestCheckRules()
Dim myPage As testWebPage = New testWebPage
myPage.testSession()
End Sub
End Class
Public Class testWebPage
Inherits System.Web.UI.Page
Public Sub New()
End Sub
Public Sub testSession()
Dim firstName As String = "John"
Dim lastName As String = "Smith"
Dim city As String = "Seattle"
Session("FirstName") = firstName
Session("LastName") = lastName
Session("City") = city
End Sub
End Class
Then when I ran I got the following error:
An exception of type 'System.Web.HttpException' occurred in System.Web.dll but was not handled in user code
Additional information: Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the \\ section in the application configuration.

Adding dll as reference to a webservice in vb.net in visual studio 2008

We have created a dll,which was working fine for the vb.net application, when we referred by add reference in visual studio 2008.But I need to create a webservice which will invoke this dll and so the all operations of the dll can be invoked via webservice.This is the aim of the project.I have created the webservice in vs2008 and added the reference of the dll located in the local disk.But when I try to build the webservice it throws the following error.
Could not load file or assembly 'COMWrapper, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Operating system:Windows 7 64 bit
Visual studio 2008
3.5 .Net Framework
Programming Language:Vb.net
Below is the webservice I Have created in VB
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Service
Inherits System.Web.Services.WebService
Dim oXRay As New COMClient.DLLCOMWrapper
<WebMethod()> _
Public Function TagDocWithRTFDoc(ByVal FileContent() As Byte, ByVal Ext As String) As String
Dim result As String
result = oXRay.TagDocWithRTFOutput(FileContent, Ext)
Return result
End Function
<WebMethod()> _
Public Function TagDocument(ByVal FileContent() As Byte, ByVal Ext As String) As String
Dim result As String
result = oXRay.TagDoc(FileContent, Ext)
Return result
End Function
<WebMethod()> _
Public Function ConvertDocument(ByVal FileContent() As Byte, ByVal Ext As String) As String
Dim result As String
result = oXRay.ConvertDoc(FileContent, Ext)
Return result
End Function
<WebMethod()> _
Public Function Info() As String
Dim result As String
result = oXRay.GetLicenseInfo
Return result
End Function
End Class

class modules in asp.net file system website

I have a class module in my App_code folder.
Private _connection As MySqlConnection
Private _connStr As String
Public Function Connect(dbName As String) As Boolean
Try
_connStr = "Database=" & dbName & ";" & _
"Data Source=192.16.0.1;" & _
"User Id=user;Password=pass"
_connection = New MySqlConnection(_connStr)
_connection.Open()
_connection.Close()
Return True
Catch ex As Exception
_connection = Nothing
Return False
End Try
Return False
End Function
I usually program in webform apps. Why can't I access this function from my aspx code behind pages? I added the import statement for the class. If i make that function shared I cant have those private variables.
I call the function in my aspx lik so;
If Connect(dbName) then....
That gets me an error "non shared member requires an object reference"
You need to add the keyword "Shared" to the method signature, like so:
Private Shared _connection As MySqlConnection
Private Shared _connStr As String
Public Shared Function Connect(dbName As String) As Boolean
This is because otherwise you have instance class members, not static members. The compiler error message is quite self-explanatory.
if you look at this example works:
Public Shared Function example123(ByVal USER As Integer, ByVal Section As String, ByVal ACTION As String) As Boolean
you assign a function shared so you can see it from outside the class
I hope you work

ASP.NET Web Service + Module + Public variable = thread safe?

In my ASP.NET Web Service I've included a module in which their are Public declared variables. Will they be thread-safe? Will they get mixed up upon simultaneous calls?
Those variables are mostly DatsSet, DataTable and SQLDataAdapter..
Partial code of the module:
Imports System.Data.OleDb
Imports System.Diagnostics
Module modCommon
Public bDoLog As Boolean
Public sCurrentODBC As String
Public cn As SqlConnection
Public Query1ds As DataSet
Public Query1 As DataTable
Public Query1adapter As SqlDataAdapter
#scripni
Thanks, as I'm not familiary with your suggestions, I will move everything locally.
Additionally, will the following variables be thread-safe?:
[ToolboxItem(False)]_
Public Class Service1
Inherits System.Web.Services.WebService
Dim sName As String
Dim sCurrentPath As String
[WebMethod()]_
Public Function Capture(ByVal sPath As String) As String
sName = "Joe"
End Function
End Class
If you're using web services than yes, you will have concurency problems when multiple services will try to access the same resource, and SqlConnection is definetly a resource you don't want shared.
You should make sure that you don't have simultaneous calls to the properties (for ex. by wrapping the fields with getters / setters and implementing locks in those methods) or by moving the code to a class and instantiating that class whenever you need it.

Resources