What mstrConnection should I use on a webpage to access local SQL Server Express (localhost\SQLEXPRESS)? - sql-server-2008-express

Would the following suffice?
Dim mstrConnection As String =
"workstation id=COMPUTER;packet size=4096;data source=localhost\SQLEXPRESS;
integrated security=false;user id=x309-PC\x309;password=abc"

You should be able to get away with a simpler connection string like the following:
Data Source=(local)\SQLExpress;Initial Catalog=myDatabaseName;User ID=myUsername;Password=myPassword;
You also need to make sure in the SQL server security logins you have both mapped the user to a SQL login as well as given the user rights to the database you are interacting with. You can download MS SQL management studio express 2008 to view and set these settings.

Related

Apply SQL Server schema after 'schema compare' show error

Versions in use:
SQL Server 2016
Azure Data Studio 1.36.2
SQL Server Schema Compare 1.13.1
Problem: there is something wrong with my Azure Data Studio apply schema to SQL Server 2016.
It say I'm not the login manager but there is no login manager role in SQL Server.
And it has worked before updating Azure Data Studio to v1.36.X
https://imgur.com/a/JFWFOtn
Finally, I found the problem
Misused sqllinlinetablevaluedfunction and sqlmultistatementtablevaluedfunction
In my project There are many function use sqllinlinetablevaluedfunction instead of sqlmultistatementtablevaluedfunction but It's should be used sqlmultistatementtablevaluedfunction
so I change to Correct Type then It's worked. The error never show

Connecting to integrated SQL Server in Visual Studio 2016

I'm trying to use OLE DB to connect to the SQL Server that shipped with VS2015 (this should be SQL Server Express I think). Actually I have problems getting my connection string set up. All my attempts resulted in a generic error message.
The errors occurred with this line of code afterwards:
oCon = New OleDbConnection(cConnectstring)
I tried following connection strings:
Server=localhost;Database=main_Table;Trusted_Connection=True;
As well as:
Provider=SQLNCLI11;Data Source=(localdb)\MSSQLLocalDB;DataTypeCompatibility=80;Initial Catalog=main_Table;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False
Or:
Provider = sqloledb;Data Source=(localdb)\MSSQLLocalDB; Initial Catalog = main_Table;Integrated Security=SSPI;
where main_Table is the table I try to start with. I used the connection string that I get via right click on that table in the DB explorer as well (that worked for my Access DBs flawlessly).
Does anybody know how to make this work with Ole DB and SQL Server 2016?
Thanks.

migrating multiple linked server from one server to another on sql server 2008 R2

I have 25 linked server(which will connect remote sql server 2000) working perfectly on one server, i even don't know login information of those linked server. My current environment is sql server 2008 R2, my new environment is also sql server 2008 R2 , i just need to migrate all linked server from old to new, preserving all login information
Possible?
If you're dealing with linked servers that have specific users specified with password then I don't think you'll be able to preserve that password information. Since linked servers are at the server level that information wouldn't be in any db backup. But, you could run queries like the one below to get the list of linked servers and check which ones use pass-through credentials. For the ones that do, just create new linked server definitions in the new database (you can easily get this SQL by right-clicking on the linked server in SSMS and generating the script). For the ones that don't, you can create the linked server via TSQL but you'll have to give them new credentials.
SELECT
serv.NAME,
serv.product,
serv.provider,
serv.data_source,
serv.catalog,
prin.name,
ls_logins.uses_self_credential,
ls_logins.remote_name
FROM
sys.servers AS serv
LEFT JOIN sys.linked_logins AS ls_logins
ON serv.server_id = ls_logins.server_id
LEFT JOIN sys.server_principals AS prin
ON ls_logins.local_principal_id = prin.principal_id

can not retrieve data from sql server

I can not retrieve data from db in sql server.
I use the c3p0 as the pool,this is the c3p0.properties:
c3p0.user=test
c3p0.password=123456
c3p0.jdbcUrl=jdbc:sqlserver://xxxxxx:1433;databaseName=TIMDB;SelectMethod=cursor
c3p0.driverClass=com.microsoft.sqlserver.jdbc.SQLServerDriver
c3p0.maxPoolSize=15
c3p0.testConnectionOnCheckin=true
c3p0.idleConnectionTestPeriod=3600
In the sql server,I have create a new user named test,and its default db is TIMDB,the server roles is public,and this is the user mapping:
But when I start the application,I can get nothing.
From the log created by log4j,I can get the sql used to retrieve data,but if I copy the sql to the sql management stutio and create a new query,I can retrieve some data.
I wonder why?
It looks like a permissions problem to me. If the generated SQl runs when you use it in management studio (i.e under your user account) then you know the code is good. What access have you given the user "test" from your post I see "user mapping: enter image description here"? he will need at least db_datareader and possibly more depending on what code is generated.
You could also try logging on to SQL Management studio under your "test" user and see if you can execute the code. That will eliminate the possibility that its something wrong with your application/network.

how to access sql server from asp page

We have a legacy, homegrown timesheet system (ASP, microsoft sql server 2005) that I need to clone to another computer for backup purposes. (I know very little about this stuff, so pleas be gentle)
I've got most of the pieces in place (IIS, Sql Server, table import / creation). But, the ASP page to access the timesheet pages is choking on access to the sql server.
here is the line it's crashing on: conn.open Session("sConnStr")
This is the connection string;
sConnStr = "Server=MYSERVER-D01;DATABASE=MYDATABASE;UID=MyDatabaseUser;PWD=MyDatabaseUser;QuotedID=No;DRIVER={SQL Server};Provider=MSDASQL"
This is the error:
Error Type: Microsoft OLE DB Provider for ODBC Drivers (0x80004005) [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified /mydir/mypage.asp, line 17 <== shown above
Note that am able to access the db on SQL Server with Windows specified as the authentication using Server Management Studio. However, when i try using SQL Authentication, I get the message "The user is not associated with a trusted SQL connection".
Questions:
How do you set up the user / password on SQL Server 2005?
What is the default driver, and do i need to get it/set it up?
When it talks about the data source name ( see "MYDATABASE" in the
above mentioned connection string), is it talking about one of the
entries you see under "Databases" on the management studio object
explorer?
Thanks for you responses! So far, no luck. I've managed to access the database via management studio object explorer, by doing this;
Enable SQL Authentication:
....Solution
To resolve this issue, follow the instructions to set User Authentication.
SQL Server 2000:
Go to Start > Programs > Microsoft SQL Server > Enterprise Manager
Right-click the Server name, select Properties > Security
Under Authentication, select SQL Server and Windows
The server must be stopped and re-started before this will take effect
SQL Server 2005:
Go to Start > Programs > Microsoft SQL Server 2005 > SQL Server Management Studio
Right-click the Server name, select Properties > Security
Under Server Authentication, select SQL Server and Windows Authentication Mode
The server must be stopped and re-started before this will take effect..."
And
this;
Change the owner to the one being used to access the db
Microsoft SQL Server Management Studio
Right click the DB, change the owner
But I'm still getting exactly the same error message!
To create a new user and assign it to a database you'll need to do the following,
In SQL Server Management Studio, open Object Explorer and expand the
folder of the server instance in which
to create the new login.
Right-click the Security folder, point to New, and then click Login.
On the General page, enter a name for the new login in the Login name
box.
Select SQL Server Authentication. Windows Authentication is the more
secure option.
Enter a password for the login.
Select the password policy options that should be applied to the new
login. In general, enforcing password
policy is the more secure option.
Click OK.
You will then want to assign that login to a database by creating a new database user,
In SQL Server Management Studio, open Object Explorer and expand the
Databases folder.
Expand the database in which to create the new database user.
Right-click the Security folder, point to New, and then click User.
On the General page, enter a name for the new user in the User name box.
In the Login name box, enter the name of a SQL Server login to map to
the database user.
Click OK.
You'll want to make that user the db_owner. Run the following against your database.
sp_addrolemember #rolename = 'db_owner', #membername = 'usernamehere'
Then use the following connection string format to connect to the database.
Data Source=ServerAddress;Initial Catalog=DatabaseName;User Id=UserName;Password=UserPassword;
If you have a trusted connection from the login that IIS is using the the machine that has SQL Server running on it I would avoid using Username / Password and declare that the connection is trusted in your connection string:
sConnStr = "Server=MYSERVER-D01;DATABASE=MYDATABASE;UID=MyDatabaseUser;PWD=MyDatabaseUser;QuotedID=No;DRIVER={SQL Server};Provider=MSDASQL;Integrated Security=SSPI"
This is to illustrate the change, but in practice you may need to vary the connections string a bit more than that, have a look at http://www.connectionstrings.com/sql-server-2005 for examples.
When it talks about the data source name ( see "MYDATABASE" in the above mentioned connection string), is it talking about one of the entries you see under "Databases" on the management studio object explorer
Yes, your entry for "MYDATABASE" should be the exact name of the database that you see under "Databases". Make sure that you have the "Server" correct too.
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC Driver Manager]Data source name not found and no default driver specified.
This usually happens in one of the following scenarios:
* you referenced your connection incorrectly (e.g. spelled the DSN name, or one of the DSN-less string components wrong);
* you referenced a DSN that doesn't exist;
* the user connecting to the DSN or DSN-less connection doesn't have access to the information stored in the registry (see KB #306345);
* you used an English or localized driver detail for your connection string when your system is not set up in that language (see KB #174655); or,
* you are missing the connection string entirely (this can happen if you maintain your connection string in a session variable, and your sessions aren't working; see Article #2157).
Here is the link to the above article (note it is extremely detailed).
link
To answer the last question, MYDATABASE is calling a database by name. If you use 'MYDATABASE' in your string, you will need a database named 'MYDATABASE' in SQL Server.
This connection string should work fine with ASP if this is a SQL server. Replace your values before using obviously.
sConnStr = "provider=SQLOLEDB;Data Source=YourServerName;Initial Catalog=YourDBName;UID=YourUserName;PWD=YourUserPWD;"
The easiest way I have found to deal with these issue is to create a udl file. On your desktop create a new text file and rename it filename.udl. Double click the udl file. Click the Provider Tab > select Microsoft OLE DB Provider for SQL Server > Next. Using the connection tab you should be able to connect to your database. Once test connection succeeds click ok. You can now open the file in a text editor and copy and paste the line that start Provider... to your asp file. You should end up with sConnStr = "Provider..textfromUDLfile"
MSDN - Creating and Configuring Universal Data Link (.udl) Files
I suggest that you create a DAL (Data Access Layer) that can do all the connection stuff for you. Just passit your command an dit can open and close your conenctions and such. In any app you wan tto abstract these different layers as much as posible and that means that your aspx page should call to an object when has the methods that hten get handled by the dal and make the database calls.
Here is the format for connection to the DB. You can put the connecitn string in the web.config file or even do it in code using hte connectionstringbuilder.
you also need to make sure that your project includes the system.data.sqlclient library otherwise this won't work.
The entry in the web config file looks something like this.
<add name="ConString" connectionString="Data Source=localhost;Integrated Security=True;Initial Catalog="DBtouse";Persist Security Info=True;" providerName="System.Data.SqlClient"/>
or
<add key="ConString" value="Server=localhost;user=username;password=password;Initial Catalog=MyDBtouse;pooling=false"/>
the code behind loks like this:
Dim MyConnection As Data.SqlClient.SqlConnection
Dim Constring As New SqlClient.SqlConnectionStringBuilder
Constring.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings("ConString")
Constring.ConnectTimeout = 30
MyConnection.ConnectionString = Constring.ConnectionString
MyConnection.Open()
'Execute code here
MyConnection.Close()
MyConnection = Nothing