Så här ser min kod ut: Öppna "Enterprise Manager" (för SQL server). Prova även följande: THere are a few things to think about before deciding on which type of solution to your problem you want to use, Tack så mycket, jag fick ordning på det tillslut på just det sättet!Jag har problem med att koppla mot SQL Db.. Jag är N00b så, bear with
----------------------------------------------------------------------------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Skapa connectionobjektet med connectionstring i parentesen
Dim cn As New SqlConnection("Server=localhost;Database=DiaryDb;Trusted_Connection=True;")
' Skapa SQL-satsen
Dim strSql As String = "SELECT * FROM Fnamn"
' Dimensionera en dataadapter
Dim adpAdapter As New SqlDataAdapter(strSql, cn)
' Fyll datasetet
adpAdapter.Fill(dsDataset)
TextBox1.Text = dsDataset.Tables(0).Rows(0).Item(0)
TextBox2.Text = dsDataset.Tables(0).Rows(0).Item(1)
End Sub
Felmeddelandet jag får ser ut så här:
----------------------------------------------------------------------------------------------
Login failed for user 'MINBURK\ASPNET'.
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: Login failed for user 'MINBURK\ASPNET'.
Source Error:
Line 45:
Line 46: ' Fyll datasetet
Line 47: adpAdapter.Fill(dsDataset)
Line 48:
Line 49: TextBox1.Text = dsDataset.Tables(0).Rows(0).Item(0)
---------------------------------------------------------------------------------------------
Varför vill det sig inte? Jag antar att det har med vart min Db ligger? hur ser jag det? och jag skall ju inte ha ett lösen på den vad jjag et, utan den skall ju vara "öppen"..
Jag kommer inte vidare, kan nån hjälpa mig?
Tack skall ni ha..
Kim.Sv: Jag har problem med att koppla mot SQL Db.. Jag är N00b så, bear w
Expander trädet till SQL Servern.
Högerklicka och välj "Properties".
Klicka på fliken "Security".
Kolla vad som är angivet under "Authentication".
Det ska vara "SQl Server and Windows" för att det ska fungera.
Du kan också prova att ändra din anslutningssträng till
<code>
Dim cn As New SqlConnection("Server=localhost;Database=DiaryDb;UID=sa;PWD=")
</code>
för att se om det fungerar.Sv: Jag har problem med att koppla mot SQL Db.. Jag är N00b så, bear
<code>
Dim cn As New SqlConnection("Data Source=localhost;Initial Catalog=DiaryDB;Integrated Security=SSPI;")
' Skapa SQL-satsen
Dim strSql As String = "SELECT * FROM Fnamn"
' Dimensionera en dataadapter
Dim adpAdapter As New SqlDataAdapter(strSql, cn)
' Fyll datasetet
Dim dsdataset As DataSet = New DataSet
adpAdapter.Fill(dsdataset)
MessageBox.Show("Done")
</code>Sv: Jag har problem med att koppla mot SQL Db.. Jag är N00b så, bear w
Security for one,
if your using sql 2000 then you should not really be using SQL Server and Windows security but only use windows NT security, you can see in 2k you only have to choices.
If the sql server your connecting to is on the same machine as your application then the MachineName/aspnet can work but if your app is trying to connect to the sql server that's on another machine then the macinhe naem/aspnet user can never be set up properly.
Also when useing a connection string with user credentials ( userAcc & Password ) your should try to always use something like the following example where you tell the connection ado object not to show in ascii the user credentials over the lan
ex:
Constring = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=UsrName;password=Password;Initial Catalog=DBname;Data Source=SQLservername"
For more info on connection string try here www.connectionstrings.com , they go everything you might need.
I had some of the same problems your experiencing, the way I fixed it was two stages,
1) Set up a LAN user or local user on the sqlserver ( LAN User Preferred )
2) In the web.config add this parameter
<identity impersonate="true" UserName="DomainOrMachineName\SomeUser" password="SomePassword"></identity>
(you should read .Net dox about imersonation this usage )
Then on the sql server added the user to the loacl OS user manager,
After this I was ok,
Also I went into the sql server enterprise manager and explicitly set the new user to have access to the required views / tables and stored Procedures.
I know this is a lot to think about but if you start off by doing things with security in mind it might save time in the future
Also MS have a .net data component which I use most of the time, you can get it here
http://www.microsoft.com/downloads/details.aspx?FamilyID=f63d1f0a-9877-4a7b-88ec-0426b48df275&DisplayLang=en
It saves a lot of time coding.
I did find that if used from ASP.net then you should pass the connection object to the sqlhelper class, other wise you can end up with closed connections when you do thing you should have.
Good luck Paul
All information given is to be view and used at your own risk.
Paul Horsley takes no responsibility for content given or recieved.Sv: Jag har problem med att koppla mot SQL Db.. Jag är N00b så, bear
Tack.