Hi:
I'm trying to connect to a data base of "sql server 2005 enterprise" named BCR.
The server name is "server1"
I'm using Windows Authentication to connect to server
The operating system is Windows Server 2003 Enterprise Edition Service Pack 1
When I run the aspx I get this error at line 21
System.Data.OleDb.OleDbException: Invalid authorization specification Invalid connection string attribute at System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr) at System.Data.OleDb.OleDbConnection.InitializeProvider() at System.Data.OleDb.OleDbConnection.Open() at ASP.pruebaLeeSqlServer_aspx.__Render__control1(HtmlTextWriter __output, Control parameterContainer) in Z:\Digital\pruebaLeeSqlServer.aspx:line 21
This is my code:
Dim str2 As String = "Provider=SQLNCLI; Server = server1; Database = BCR"
Dim cnn2 As OleDbConnection = New OleDbConnection(str2)
Dim cmd2 As New OleDbCommand()
Dim drd2 As OleDbDataReader
Try
cnn2.Open()
cmd2.Connection = cnn2''''line 21
cmd2.CommandText ="SELECT LastName FROM Employees"
drd2 = cmd2.ExecuteReader
Do While drd2.Read
%>
<%=drd2.GetString(0)%><br>
<%
Loop
drd2.Close()
Catch exc1 As Exception
%>
<%=exc1.ToString()%>
<%
Finally
cnn2.Close()
End Try
What could be wrong?
Do I need enable permission for asp.net in sql server?
how I can do it?
Thanks!!
You should be using the objects in the System.Data.SqlClient namespace to connect to MS SQL Server, not System.Data.OleDb. That should fix your issue given that there is no problem with your connection string.
HTH,
Ryan
I are right, I had to use System.Data.SqlClient namespace instead of System.Data.OleDb. And I just change my connection string to
"Server=server1; Database=BCR; Trusted_Connection=True;"
Thanks!
No comments:
Post a Comment