Need Help connection String

M

Mark Fitzpatrick

Don't use localhost. Try using (local) instead keeping the paranthases ().

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

Justnew said:
Hei All

Can some body help me here: I have a database name Customers, I am
trying to connect to SQL server through vb.net using asp.net webform.
I want to connect to the server programatically this is my connection
string:

Private strsql As String
Private strconnection As String = "data source=localhost;initial
catalog=Customers;integrated security=SSPI;persist security
info=False;workstation id=localhost;packet size=4096"

Public Function newCustomer(ByVal Fornavn As String, ByVal Etternavn
As String, ByVal Adresse As String, ByVal PostNr As String, ByVal
PostSted As String, ByVal Telefon As String, ByVal Epost As String,
ByVal Kjønn As String) As String
strsql = "exec NyKunde '" & Fornavn & "','" & Etternavn & "','"
& Adresse & "','" & PostNr & "','" & PostSted & "','" & Telefon & "','"
& Epost & "','" & Kjønn & "'"


Dim conn As SqlConnection = New SqlConnection(strconnection)
conn.Open()
Dim com As SqlCommand = New SqlCommand(strsql, conn)


Try
com.ExecuteNonQuery()
Catch e As SqlException
MsgBox(strsql)
MsgBox(e.ToString)
Throw (e)
Finally
conn.Close()

End Try

End Function

I have use this same method with Windows application, but this does not
seems to work on web application

when I run this application I am getting the following error


Server Error in '/Customers' Application.
-------------------------------------------------------------------------- ------

SQL Server does not exist or access denied.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: SQL Server does
not exist or access denied.

Source Error:


Line 13:
Line 14: Dim conn As SqlConnection = New
SqlConnection(strconnection)
Line 15: conn.Open()
Line 16: Dim com As SqlCommand = New SqlCommand(strsql, conn)
Line 17:


Source File: c:\inetpub\wwwroot\Customers\db.vb Line: 15

Stack Trace:


[SqlException: SQL Server does not exist or access denied.]
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction)

System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnec
tionString
options, Boolean& isInTransaction)
System.Data.SqlClient.SqlConnection.Open()
Customers.db.RegNyKunde(String Fornavn, String Etternavn, String
Adresse, String PostNr, String PostSted, String Telefon, String Epost,
String Kjønn) in c:\inetpub\wwwroot\Customers\db.vb:15
Customers.WebForm1.leggtilKunde() in
c:\inetpub\wwwroot\Customers\WebForm1.aspx.vb:57
Customers.WebForm1.btnsubmit_Click(Object sender, EventArgs e) in
c:\inetpub\wwwroot\Customers\WebForm1.aspx.vb:62
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
stBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()


Justnew
 
M

Michael Ramey

try this connectionstring

"SERVER=localhost;DATABASE=Customers;Integrated Security=SSPI;persist
security info=False;packet size=4096"

Also, where is the SQL Server you are trying to connect to?

I hope it is local on the machine you are running this code from
"localhost", and I hope it doesn't have an instance name. If it is local,
open the Service Manager in your system tray, and replace localhost with
whatever is says in the "Server" field

HTH,
--Michael

Justnew said:
Hei All

Can some body help me here: I have a database name Customers, I am
trying to connect to SQL server through vb.net using asp.net webform.
I want to connect to the server programatically this is my connection
string:

Private strsql As String
Private strconnection As String = "data source=localhost;initial
catalog=Customers;integrated security=SSPI;persist security
info=False;workstation id=localhost;packet size=4096"

Public Function newCustomer(ByVal Fornavn As String, ByVal Etternavn
As String, ByVal Adresse As String, ByVal PostNr As String, ByVal
PostSted As String, ByVal Telefon As String, ByVal Epost As String,
ByVal Kjønn As String) As String
strsql = "exec NyKunde '" & Fornavn & "','" & Etternavn & "','"
& Adresse & "','" & PostNr & "','" & PostSted & "','" & Telefon & "','"
& Epost & "','" & Kjønn & "'"


Dim conn As SqlConnection = New SqlConnection(strconnection)
conn.Open()
Dim com As SqlCommand = New SqlCommand(strsql, conn)


Try
com.ExecuteNonQuery()
Catch e As SqlException
MsgBox(strsql)
MsgBox(e.ToString)
Throw (e)
Finally
conn.Close()

End Try

End Function

I have use this same method with Windows application, but this does not
seems to work on web application

when I run this application I am getting the following error


Server Error in '/Customers' Application.
-------------------------------------------------------------------------- ------

SQL Server does not exist or access denied.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: SQL Server does
not exist or access denied.

Source Error:


Line 13:
Line 14: Dim conn As SqlConnection = New
SqlConnection(strconnection)
Line 15: conn.Open()
Line 16: Dim com As SqlCommand = New SqlCommand(strsql, conn)
Line 17:


Source File: c:\inetpub\wwwroot\Customers\db.vb Line: 15

Stack Trace:


[SqlException: SQL Server does not exist or access denied.]
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction)

System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnec
tionString
options, Boolean& isInTransaction)
System.Data.SqlClient.SqlConnection.Open()
Customers.db.RegNyKunde(String Fornavn, String Etternavn, String
Adresse, String PostNr, String PostSted, String Telefon, String Epost,
String Kjønn) in c:\inetpub\wwwroot\Customers\db.vb:15
Customers.WebForm1.leggtilKunde() in
c:\inetpub\wwwroot\Customers\WebForm1.aspx.vb:57
Customers.WebForm1.btnsubmit_Click(Object sender, EventArgs e) in
c:\inetpub\wwwroot\Customers\WebForm1.aspx.vb:62
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
stBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()


Justnew
 
J

Justnew

Hei All

Can some body help me here: I have a database name Customers, I a
trying to connect to SQL server through vb.net using asp.net webform.
I want to connect to the server programatically this is my connectio
string:

Private strsql As String
Private strconnection As String = "data source=localhost;initia
catalog=Customers;integrated security=SSPI;persist securit
info=False;workstation id=localhost;packet size=4096"

Public Function newCustomer(ByVal Fornavn As String, ByVal Etternav
As String, ByVal Adresse As String, ByVal PostNr As String, ByVa
PostSted As String, ByVal Telefon As String, ByVal Epost As String
ByVal Kjønn As String) As String
strsql = "exec NyKunde '" & Fornavn & "','" & Etternavn & "','
& Adresse & "','" & PostNr & "','" & PostSted & "','" & Telefon & "','
& Epost & "','" & Kjønn & "'"


Dim conn As SqlConnection = New SqlConnection(strconnection)
conn.Open()
Dim com As SqlCommand = New SqlCommand(strsql, conn)


Try
com.ExecuteNonQuery()
Catch e As SqlException
MsgBox(strsql)
MsgBox(e.ToString)
Throw (e)
Finally
conn.Close()

End Try

End Function

I have use this same method with Windows application, but this does no
seems to work on web application

when I run this application I am getting the following error


Server Error in '/Customers' Application.
--------------------------------------------------------------------------------

SQL Server does not exist or access denied.
Description: An unhandled exception occurred during the execution o
the current web request. Please review the stack trace for mor
information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: SQL Server doe
not exist or access denied.

Source Error:


Line 13:
Line 14: Dim conn As SqlConnection = Ne
SqlConnection(strconnection)
Line 15: conn.Open()
Line 16: Dim com As SqlCommand = New SqlCommand(strsql, conn)
Line 17:


Source File: c:\inetpub\wwwroot\Customers\db.vb Line: 15

Stack Trace:


[SqlException: SQL Server does not exist or access denied.]
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean
isInTransaction)

System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionStrin
options, Boolean& isInTransaction)
System.Data.SqlClient.SqlConnection.Open()
Customers.db.RegNyKunde(String Fornavn, String Etternavn, Strin
Adresse, String PostNr, String PostSted, String Telefon, String Epost
String Kjønn) in c:\inetpub\wwwroot\Customers\db.vb:15
Customers.WebForm1.leggtilKunde() i
c:\inetpub\wwwroot\Customers\WebForm1.aspx.vb:57
Customers.WebForm1.btnsubmit_Click(Object sender, EventArgs e) i
c:\inetpub\wwwroot\Customers\WebForm1.aspx.vb:62
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(Strin
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandle
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain(

Justne
 
J

Justnew

Thank you for the reply I have replace the instance name as exactly a
it is in the service manager, now when I tried to run the applicatio
this error Iam receiving. I have used mix mode in the authention

Server Error in '/Customers' Application.
--------------------------------------------------------------------------------

Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.
Description: An unhandled exception occurred during the execution o
the current web request. Please review the stack trace for mor
information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Login failed fo
user 'NT AUTHORITY\NETWORK SERVICE'.

Source Error:


Line 13:
Line 14: Dim conn As SqlConnection = Ne
SqlConnection(strconnection)
Line 15: conn.Open()
Line 16: Dim com As SqlCommand = New SqlCommand(strsql, conn)
Line 17:


Source File: c:\inetpub\wwwroot\Customers\db.vb Line: 15

Stack Trace:


[SqlException: Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.]
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean
isInTransaction)

System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionStrin
options, Boolean& isInTransaction)
System.Data.SqlClient.SqlConnection.Open()
Customers.db.RegNyKunde(String Fornavn, String Etternavn, Strin
Adresse, String PostNr, String PostSted, String Telefon, String Epost
String Kjønn) in c:\inetpub\wwwroot\Customers\db.vb:15
Customers.WebForm1.leggtilKunde() i
c:\inetpub\wwwroot\Customers\WebForm1.aspx.vb:57
Customers.WebForm1.btnsubmit_Click(Object sender, EventArgs e) i
c:\inetpub\wwwroot\Customers\WebForm1.aspx.vb:62
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(Strin
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandle
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain




Michael said:
*try this connectionstring

"SERVER=localhost;DATABASE=Customers;Integrate
Security=SSPI;persist
security info=False;packet size=4096"

Also, where is the SQL Server you are trying to connect to?

I hope it is local on the machine you are running this code from
"localhost", and I hope it doesn't have an instance name. If it i
local,
open the Service Manager in your system tray, and replace localhos
with
whatever is says in the "Server" field

HTH,
--Michael

Justnew said:
Hei All

Can some body help me here: I have a database name Customers, I am
trying to connect to SQL server through vb.net using asp.ne webform.
I want to connect to the server programatically this is m connection
string:

Private strsql As String
Private strconnection As String = "data source=localhost;initial
catalog=Customers;integrated security=SSPI;persist security
info=False;workstation id=localhost;packet size=4096"

Public Function newCustomer(ByVal Fornavn As String, ByVa Etternavn
As String, ByVal Adresse As String, ByVal PostNr As String, ByVal
PostSted As String, ByVal Telefon As String, ByVal Epost A String,
ByVal Kjønn As String) As String
strsql = "exec NyKunde '" & Fornavn & "','" & Etternavn & "','"
& Adresse & "','" & PostNr & "','" & PostSted & "','" & Telefon "','"
& Epost & "','" & Kjønn & "'"


Dim conn As SqlConnection = New SqlConnection(strconnection)
conn.Open()
Dim com As SqlCommand = New SqlCommand(strsql, conn)


Try
com.ExecuteNonQuery()
Catch e As SqlException
MsgBox(strsql)
MsgBox(e.ToString)
Throw (e)
Finally
conn.Close()

End Try

End Function

I have use this same method with Windows application, but this doe not
seems to work on web application

when I run this application I am getting the following error


Server Error in '/Customers' Application.
--------------------------------------------------------------------------
------

SQL Server does not exist or access denied.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: SQL Server does
not exist or access denied.

Source Error:


Line 13:
Line 14: Dim conn As SqlConnection = New
SqlConnection(strconnection)
Line 15: conn.Open()
Line 16: Dim com As SqlCommand = New SqlCommand(strsql, conn)
Line 17:


Source File: c:\inetpub\wwwroot\Customers\db.vb Line: 15

Stack Trace:


[SqlException: SQL Server does not exist or access denied.]
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction)

System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnec
tionString
options, Boolean& isInTransaction)
System.Data.SqlClient.SqlConnection.Open()
Customers.db.RegNyKunde(String Fornavn, String Etternavn, String
Adresse, String PostNr, String PostSted, String Telefon, String Epost,
String Kjønn) in c:\inetpub\wwwroot\Customers\db.vb:15
Customers.WebForm1.leggtilKunde() in
c:\inetpub\wwwroot\Customers\WebForm1.aspx.vb:57
Customers.WebForm1.btnsubmit_Click(Object sender, EventArgs e) in
c:\inetpub\wwwroot\Customers\WebForm1.aspx.vb:62
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
stBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()


Justnew
------------------------------------------------------------------------
Posted via http://www.mcse.ms
------------------------------------------------------------------------
View this thread: http://www.mcse.ms/message346156.html
*


Justnew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top